476. Number Complement
来源:互联网 发布:指针指向字符串数组 编辑:程序博客网 时间:2024/06/07 11:28
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.
class Solution {
public:
int findComplement(int num) {
unsigned mask = ~0;
while (num & mask)
mask <<= 1;
return ~mask & ~num;
}
};
阅读全文
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)
- HDU-1864-最大报销额
- ElasticSearch之ANSJ分词器搭建搭建,解决ansj停止词bug (qq交流群 189040279)
- VMRC开启拷贝粘贴
- 《Linux内核设计与实现》读书笔记(七)- 中断处理
- 利用GlobalMapper实现DGSinfo野外地质填图系统的图像快速配准与集成
- 476. Number Complement
- 移动web开发框架研究
- const char* 转成 CString类型
- eclipse并行和vSphere虚拟机设置问题(一)
- HTML Responsive Web Page
- C/C++ 笔试面试(1)—— sizeof 非常实用的资料
- jQuery Ajax 实例 ($.ajax、$.post、$.get)
- C/C++ 笔试面试(2)——二分查找 的确遇到的笔试题
- javascript基础_02