求十进制数的反码

通过观察可知,输入与输出的关系为:

Input+Output=LeetCode_1021_ Complement of Base 10 Integer

其中n为使LeetCode_1021_ Complement of Base 10 IntegerLeetCode_1021_ Complement of Base 10 IntegerInput+Output成立的最小m值

class Solution {
public:
    int bitwiseComplement(int N) {
		if(N<=1) return 1-N;
        int cnt=1;
		while(cnt<=N)
			cnt=cnt*2;
		return cnt-1-N;
    }
};

注意对N=0,1时的特殊情况讨论即可。

LeetCode_1021_ Complement of Base 10 Integer

相关文章:

  • 2022-12-23
  • 2021-11-17
  • 2021-07-06
  • 2021-04-22
  • 2021-08-23
  • 2022-02-23
  • 2022-12-23
猜你喜欢
  • 2021-10-15
  • 2022-12-23
  • 2022-12-23
  • 2022-03-04
  • 2021-09-12
  • 2022-12-23
  • 2021-08-27
相关资源
相似解决方案