File tree 2 files changed +20
-0
lines changed
2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change 143
143
451|[ Sort Characters By Frequency] ( ./0451-sort-characters-by-frequency.js ) |Medium|
144
144
452|[ Minimum Number of Arrows to Burst Balloons] ( ./0452-minimum-number-of-arrows-to-burst-balloons.js ) |Medium|
145
145
459|[ Repeated Substring Pattern] ( ./0459-repeated-substring-pattern.js ) |Easy|
146
+ 461|[ Hamming Distance] ( ./0461-hamming-distance.js ) |Easy|
146
147
463|[ Island Perimeter] ( ./0463-island-perimeter.js ) |Medium|
147
148
476|[ Number Complement] ( ./0476-number-complement.js ) |Easy|
148
149
500|[ Keyboard Row] ( ./0500-keyboard-row.js ) |Easy|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments