File tree 2 files changed +22
-0
lines changed
2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change 89
89
448|[ Find All Numbers Disappeared in an Array] ( ./0448-find-all-numbers-disappeared-in-an-array.js ) |Easy|
90
90
451|[ Sort Characters By Frequency] ( ./0451-sort-characters-by-frequency.js ) |Medium|
91
91
459|[ Repeated Substring Pattern] ( ./0459-repeated-substring-pattern.js ) |Easy|
92
+ 476|[ Number Complement] ( ./0476-number-complement.js ) |Easy|
92
93
500|[ Keyboard Row] ( ./0500-keyboard-row.js ) |Easy|
93
94
541|[ Reverse String II] ( ./0541-reverse-string-ii.js ) |Easy|
94
95
551|[ Student Attendance Record I] ( ./0551-student-attendance-record-i.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 476. Number Complement
3
+ * https://leetcode.com/problems/number-complement/
4
+ * Difficulty: Easy
5
+ *
6
+ * The complement of an integer is the integer you get when you flip all the 0's to 1's
7
+ * and all the 1's to 0's in its binary representation.
8
+ *
9
+ * For example, The integer 5 is "101" in binary and its complement is "010" which is
10
+ * the integer 2.
11
+ *
12
+ * Given an integer num, return its complement.
13
+ */
14
+
15
+ /**
16
+ * @param {number } num
17
+ * @return {number }
18
+ */
19
+ var findComplement = function ( num ) {
20
+ return parseInt ( num . toString ( 2 ) . split ( '' ) . map ( n => 1 - n ) . join ( '' ) , 2 ) ;
21
+ } ;
You can’t perform that action at this time.
0 commit comments