题解 | #懂二进制#
懂二进制
https://www.nowcoder.com/practice/120e406db3fd46f09d55d59093f13dd8
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param m int整型
* @param n int整型
* @return int整型
*/
int countBitDiff(int m, int n) {
// write code here
n = m^n;
m=0;
while(n) {
n=n&(n-1);
m++;
}
return m;
}
};
算法常用解题技巧 文章被收录于专栏
算法常用解题技巧
查看1道真题和解析