![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode Bit Manipulation
Tech In Pieces
这个作者很懒,什么都没留下…
展开
-
Bit Manipulation(位运算)技巧总结
异或的特性。第 136 题,第 268 题,第 389 题,第 421 题 x ^ 0 = x x ^ 11111……1111 = ~x x ^ (~x) = 11111……1111 x ^ x = 0 a ^ b = c => a ^ c = b => b ^ c = a (交换律) a ^ b ^ c = a ^ (b ^ c) = (a ^ b)^ c (结合律) 构造特殊 Mask,将特殊位置放 0 或 1。 将 x 最右边的 n 位清零, x & ( ~0 <<原创 2021-01-02 12:09:26 · 224 阅读 · 0 评论 -
位运算中可以使用的三个技巧
x & (-x) to keep the rightmost 1-bit and to set all the others bits to zero. application: x&(-x)==x check if x is power of 2, pay attention to potentially overflow of -x x & (x - 1) set the rightmost 1 bit as 0. application: x&(x - 1)==0原创 2020-12-17 05:59:15 · 83 阅读 · 0 评论 -
LeetCode Bit Manipulation 技巧总结
https://leetcode.com/problems/sum-of-two-integers/discuss/84278/A-summary%3A-how-to-use-bit-manipulation-to-solve-problems-easily-and-efficiently Six common bit operator & | ~ ^ >> <<...原创 2020-12-11 08:05:27 · 250 阅读 · 0 评论