public class Solution {
/**
* 获得两个整形二进制表达位数不同的数量
*
* @param m 整数m
* @param n 整数n
* @return 整型
*/
public int countBitDiff(int m, int n) {
int res = m ^ n; //字符串异或
String m1 = Integer.toBinaryString(res);//转二进制
int r = (m1 + "").replace("0","").length(); //计算1
return r;
}
}
https://www.nowcoder.com/practice/ba033b0d1c2f497da1dd04330cc003af?tpId=182&&tqId=34357&rp=1&ru=/ta/exam-all&qru=/ta/exam-all/question-ranking
京公网安备 11010502036488号