/*
* @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 -位运算
最新推荐文章于 2025-11-30 14:38:30 发布
本文介绍了解决LeetCode问题1009的C++实现,通过位操作求取十进制整数的补码,适用于理解基础数值运算在计算机中的表示。
166

被折叠的 条评论
为什么被折叠?



