LeetCode476. Number Complement位操作面试题
来源:互联网 发布:语义搜索python 编辑:程序博客网 时间:2024/04/30 10:07
Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.
Note:
- The given integer is guaranteed to fit within the range of a 32-bit signed integer.
- You could assume no leading zero bit in the integer’s binary representation.
Example 1:
Input: 5Output: 2Explanation: The binary representation of 5 is 101 (no leading zero bits), and its complement is 010. So you need to output 2.
Example 2:
Input: 1Output: 0Explanation: The binary representation of 1 is 1 (no leading zero bits), and its complement is 0. So you need to output 0.
class Solution {
public:
int findComplement(int num) {
int mask = 0xffffffff;
while (num & mask)
{
mask <<= 1;
}
return ~(num | mask);
}
};
0 0
- LeetCode476. Number Complement位操作面试题
- leetcode476: Number Complement
- leetcode476. Number Complement
- leetcode476. Number Complement
- Leetcode476. Number Complement
- leetcode476. Number Complement
- python--leetcode476. Number Complement
- 13.leetCode476:Number Complement
- 位操作-leetcode 476. Number Complement
- Number Complement:数字填充位操作
- 面试题-位操作
- 面试题:位操作
- (leetcode)位运算 Number Complement
- 位操作算法面试题
- LeetCode 476 Number Complement(位运算)
- LeetCode 简单操作 | 476. Number Complement
- 华为位操作面试题分析
- [经典面试题]位运算操作
- 2016年终总结
- 循环的跳转
- javascript基础 图片雪碧动画
- 面相对象-学习笔记-java容器与泛型
- shiro初步 shiro认证
- LeetCode476. Number Complement位操作面试题
- 使用开源软件快速搭建数据分析平台
- Camera2 openCamera
- Oracle启动EM报错的解决方法
- 【LeetCode】 398. Random Pick Index
- 77. Combinations**
- 个人笔记
- Paint the Grid Reloaded zoj3781(缩点+dfs + bfs 染色)
- 初见数据结构