476. Number Complement
来源:互联网 发布:淘宝客服分流 编辑:程序博客网 时间:2024/06/15 18:57
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) { long long mode = 1; int ans = num; while(num){ mode <<= 1; num >>= 1; } --mode; ans ^= mode; return ans; }};
0 0
- LeetCode 476. Number Complement
- leetcode 476. Number Complement
- 【Leetcode】476. Number Complement
- 【Leetcode】476. Number Complement
- 476. Number Complement*
- LeetCode 476. Number Complement
- LeetCode 476. Number Complement
- LeetCode--476. Number Complement
- LeetCode 476. Number Complement
- 476. Number Complement
- 476. Number Complement [LeetCode]
- 476. Number Complement
- [LeetCode]476.Number Complement
- 476. Number Complement
- 【LeetCode】 476. Number Complement
- LeetCode 476. Number Complement
- 476. Number Complement
- 476. Number Complement (E)
- Android应用编译打包流程
- csdn上的第一篇博客,新的技术里程的开始
- if(3 == true)
- 文字转语音
- numpy 下的数据结构与数据类型的转换(np.array vs. np.asarray)
- 476. Number Complement
- windows下使用git和github建立远程仓库
- 各大互联网公司技术博客汇总
- 在父页面调用iframe子页面的JS方法
- MySQL 触发器
- 常用web正则表达式
- android 控制移动网络开关
- Ng机器学习课程Notes学习及编程实战系列-Part 1 Linear Regression
- (转载)HTTP协议