5.6 Conversion
2015-10-29 05:23
246 查看
Note: c & (c - 1)will clear the least significant bit in c. if we need to call this equation n times to let c becomes 0, there are n 1s in c!
int bitSwapRequired(int a, int b) { // write your code here int cnt = 0; for (int tmp = a^b; tmp != 0; tmp = tmp & (tmp-1)) ++cnt; return cnt; }
相关文章推荐
- 5.1 Insertion
- 5.2 Binary to String
- 5.3 Flip Bit to Win
- 5.4 Next Number
- 5.7 Pairwise Swap
- Kd-Tree算法原理和开源实现代码
- LeetCode Expression Add Operators
- [LeetCode] Binary Tree Preorder Traversal
- iptables—icmp请求与响应规则:
- CryEngine3渲染引擎剖析
- 花10分钟看一下少走30年弯路
- 小、快、灵:康宁称雄光通信市场的秘诀
- HP Helion公有云宣布停服 放弃或是为了更好地进攻
- 桌面虚拟化,你还担心什么?
- 不疯魔,不成活,Rackspace为什么对管理云如此狂热
- 云计算每周之“红黑榜”
- 施耐德电气美国研发中心揭秘之旅
- [LeetCode] Paint House
- 现场直击VeeamON大会,“云中漫步”与“免费盛宴”