leetcode-461-easy

Hamming Distance
思路一: 求 bit 不同的位数,XOR 可以把 bit 不同的位置变成 1,再用 bitCount() 统计

public int hammingDistance(int x, int y) {
    return Integer.bitCount(x ^ y);
}
posted @ 2022-10-19 07:38  iyiluo  阅读(16)  评论(0)    收藏  举报