Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7bcfb4d

Browse files
committedDec 27, 2021
Add solution #476
1 parent 74e4a12 commit 7bcfb4d

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
448|[Find All Numbers Disappeared in an Array](./0448-find-all-numbers-disappeared-in-an-array.js)|Easy|
9090
451|[Sort Characters By Frequency](./0451-sort-characters-by-frequency.js)|Medium|
9191
459|[Repeated Substring Pattern](./0459-repeated-substring-pattern.js)|Easy|
92+
476|[Number Complement](./0476-number-complement.js)|Easy|
9293
500|[Keyboard Row](./0500-keyboard-row.js)|Easy|
9394
541|[Reverse String II](./0541-reverse-string-ii.js)|Easy|
9495
551|[Student Attendance Record I](./0551-student-attendance-record-i.js)|Easy|

‎solutions/0476-number-complement.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
};

0 commit comments

Comments
 (0)
Please sign in to comment.