/*
* @lc app=leetcode id=1009 lang=cpp
*
* [1009] Complement of Base 10 Integer
*/
// @lc code=start
class Solution {
public:
int bitwiseComplement(int n) {
if(n == 0) return 1;
int ans = 0;
int mask = 0;
while(n > 0){
if( (n&1) == 0) ans = ans | (1<<mask);
n >>= 1;
mask ++ ;
}
return ans;
}
};
// @lc code=end
No.282 - LeetCode[1009] Complement of Base 10 Integer -位运算
最新推荐文章于 2024-09-20 15:28:15 发布