461. Hamming Distance
Description
The Hamming distance between two integers is the number of positions at which the corresponding bits are different.
Given two integers x and y, calculate the Hamming distance.
Example:
1 | Input: x = 1, y = 4 |
Idea
It’s involved with bits, which bring bit operations into my mind. — xor
Code
1 | class Solution(object): |
Python
bin() example:
1 | number = 5 |
count() example:
1 | aList = [123, 'xyz', 'zara', 'abc', 123]; |