Advertisement
DeepRest

Hamming Distance

Nov 19th, 2021 (edited)
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.29 KB | None | 0 0
  1. class Solution(object):
  2.     def hammingDistance(self, x, y):
  3.         """
  4.        :type x: int
  5.        :type y: int
  6.        :rtype: int
  7.        """
  8.        
  9.         z = x ^ y
  10.         res = 0
  11.         while z > 0:
  12.             z &= z - 1
  13.             res += 1
  14.         return res
  15.            
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement