Guest User

Untitled

a guest
Oct 19th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 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. a = str(bin(x)[2:])
  9. b = str(bin(y)[2:])
  10. tempstr = ""
  11. if(len(a) > len(b)):
  12. diff = len(a) - len(b)
  13. for i in range(0, diff):
  14. tempstr += "0"
  15. b = tempstr + b
  16. elif(len(a) < len(b)):
  17. diff = len(b) - len(a)
  18.  
  19. for i in range(0, diff):
  20. tempstr += "0"
  21. a = tempstr + a
  22. count = 0
  23. for i in range(len(a)):
  24.  
  25. if a[i] != b[i]:
  26. count += 1
  27. return count
Add Comment
Please, Sign In to add comment