파이썬 알고리즘 인터뷰 71번(리트코드 461번) Hamming Distance
https://leetcode.com/problems/hamming-distance/
class Solution:
def hammingDistance(self, x: int, y: int) -> int:
bit = x ^ y
result = 0
while bit > 0:
result += bit % 2
bit = bit // 2
return result
class Solution:
def hammingDistance(self, x: int, y: int) -> int:
return bin(x ^ y).count('1')
bin 을 자주 써보지 않아서 생각나지 않았다..count 메서드가 있는 것을 머리로는 알고 있는데, 자주 써보지 않았다.