leetcode week4
来源:互联网 发布:wince小软件下载 编辑:程序博客网 时间:2024/06/06 13:03
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.
问题描述:给定一个正整数,输出为它的补,这里的补即二进制表示的每一位都取反。
解题思路:对于给定的正整数的二进制表示,我们要知道长度,然后用对应长度且全为1的二进制串取异或。因为这里无法知道具体的长度,所以可以一位一位取异或。
class Solution {public: int findComplement(int num) { long i; for(i=1;i<=num;i*=2){ num^=i; } return num; }};
0 0
- Leetcode Week4
- leetcode week4
- LeetCode Week4
- leetcode-month1-week4
- LeetCode题解 week4
- LeetCode#86 Partition List (week4)
- week4
- [leetcode 169. Majority Element]easy |week4
- Leetcode: 48.Rotate Image(Week4, Medium)
- week4-leetcode #6-ZigZag Conversion[Medium]
- LeetCode Week4:Count of Smaller Numbers After Self
- 算法设计Week4 LeetCode Algorithms Problem #207 Course Schedule
- [LeetCode-Algorithms-42] "Trapping Rain Water" (2017.9.28-WEEK4)
- [LeetCode-Algorithms-6] "ZigZag Conversion" (2017.9.28-WEEK4)
- LeetCode#74 Search a 2D Matrix(week4)
- POMM-week4
- FERMI-week4
- week4-4
- Android -- 多媒体播放之MediaPlayer使用内部实现简析
- mybatis动态插入
- mysql官方文档阅读笔记(四)Chapter 13 Functions and Operators第13章-函数和运算符
- javascript execCommand,复文本框神器
- 花布条
- leetcode week4
- STFT分析与实现
- 进程调度
- 【bzoj 1222】 [HNOI2001]产品加工
- HDU 3853 LOOPS (简单期望)
- PhpStrom xdebug
- 【Linux】Linux下的Access time/Modify time/Change time三个时间
- ARMv8引起的crash问题
- 上传插件逻辑