Skip to content

Commit

Permalink
Merge pull request Chalarangelo#426 from rohitbabugaddeti/patch-5
Browse files Browse the repository at this point in the history
update hamming_distance.md
  • Loading branch information
Trinityyi authored Feb 20, 2021
2 parents bfdb98c + c7acc67 commit 6e90052
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions snippets/hamming_distance.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ Calculates the Hamming distance between two values.

- Use the XOR operator (`^`) to find the bit difference between the two numbers.
- Use `bin()` to convert the result to a binary string.
- Convert the string to a list and use `list.count()` to count and return the number of `1`s in it.
- Convert the string to a list and use `count()` of `str` class to count and return the number of `1`s in it.

```py
def hamming_distance(a, b):
return list(bin(a ^ b)).count('1')
return bin(a ^ b).count('1')
```

```py
Expand Down

0 comments on commit 6e90052

Please sign in to comment.