## 题目列表 #### 位运算 - [231. 2的幂](https://leetcode-cn.com/problems/power-of-two/) - [338. 比特位计数](https://leetcode-cn.com/problems/counting-bits/)(难度中等) - [136. 只出现一次的数字](https://leetcode-cn.com/problems/single-number/) - [剑指 Offer 56 - I. 数组中数字出现的次数](https://leetcode-cn.com/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof/)(难度中等) - [191. 位1的个数](https://leetcode-cn.com/problems/number-of-1-bits/) - [461. 汉明距离](https://leetcode-cn.com/problems/hamming-distance/) - [190. 颠倒二进制位](https://leetcode-cn.com/problems/reverse-bits/) - [268. 丢失的数字](https://leetcode-cn.com/problems/missing-number/) - [51. N 皇后](https://leetcode-cn.com/problems/n-queens/)(难度困难) - [剑指 Offer 65. 不用加减乘除做加法](https://leetcode-cn.com/problems/bu-yong-jia-jian-cheng-chu-zuo-jia-fa-lcof/) #### 数学问题 - [7. 整数反转](https://leetcode-cn.com/problems/reverse-integer/) - [9. 回文数](https://leetcode-cn.com/problems/palindrome-number/) - [326. 3的幂](https://leetcode-cn.com/problems/power-of-three/) - [204. 计数质数](https://leetcode-cn.com/problems/count-primes/) - [29. 两数相除](https://leetcode-cn.com/problems/divide-two-integers/) - [633. 平方数之和](https://leetcode-cn.com/problems/sum-of-square-numbers/) ### 总结 1. 把一些常用的位运算特点背下来 - 与 `&`,或 `|`,非 `~`,异或 `^`,左移 `<<`,右移 `>>` - `(x & 1) == 1` 等价于 `(x % 2 == 1)` - `(x & 1) == 0` 等价于 `(x % 2 == 0)` - `x / 2` 等价于 `x >> 1` - `x &= (x - 1)` 把x最低位的二进制1给去掉 - `x & -x` 只保留最低位的1,而把其他位的1都去掉 - `x & ~x` 得到 0 2. 异或运算也是一个考点 - `x^0 = x` - `x ^ x = 0`
题目列表
位运算
数学问题
总结
&,或|,非~,异或^,左移<<,右移>>(x & 1) == 1等价于(x % 2 == 1)(x & 1) == 0等价于(x % 2 == 0)x / 2等价于x >> 1x &= (x - 1)把x最低位的二进制1给去掉x & -x只保留最低位的1,而把其他位的1都去掉x & ~x得到 0x^0 = xx ^ x = 0