Skip to content

Commit 90f5063

Browse files
committed
Add solution #461
1 parent 4328a1c commit 90f5063

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
451|[Sort Characters By Frequency](./0451-sort-characters-by-frequency.js)|Medium|
144144
452|[Minimum Number of Arrows to Burst Balloons](./0452-minimum-number-of-arrows-to-burst-balloons.js)|Medium|
145145
459|[Repeated Substring Pattern](./0459-repeated-substring-pattern.js)|Easy|
146+
461|[Hamming Distance](./0461-hamming-distance.js)|Easy|
146147
463|[Island Perimeter](./0463-island-perimeter.js)|Medium|
147148
476|[Number Complement](./0476-number-complement.js)|Easy|
148149
500|[Keyboard Row](./0500-keyboard-row.js)|Easy|

solutions/0461-hamming-distance.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* 461. Hamming Distance
3+
* https://leetcode.com/problems/hamming-distance/
4+
* Difficulty: Easy
5+
*
6+
* The Hamming distance between two integers is the number of positions at which the corresponding
7+
* bits are different.
8+
*
9+
* Given two integers x and y, return the Hamming distance between them.
10+
*/
11+
12+
/**
13+
* @param {number} x
14+
* @param {number} y
15+
* @return {number}
16+
*/
17+
var hammingDistance = function(x, y) {
18+
return (x ^ y).toString(2).replace(/0+/g, '').length;
19+
};

0 commit comments

Comments
 (0)