Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d69ea3b

Browse files
committed
adding day-four
1 parent be5944c commit d69ea3b

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# LeetCode Challenge
22

33
- May
4-
- Day 1 [First Bad Version](https://github.com/libterty/leetcode-challenge/blob/master/src/day-one/index.ts)
5-
- Day 2 [Jewels and Stones](https://github.com/libterty/leetcode-challenge/blob/master/src/day-two/index.ts)
6-
- Day 3 [Ransom Note](https://github.com/libterty/leetcode-challenge/blob/master/src/day-three/index.ts)
4+
- Day 1: [First Bad Version](https://github.com/libterty/leetcode-challenge/blob/master/src/day-one/index.ts) :unamused:
5+
- Day 2: [Jewels and Stones](https://github.com/libterty/leetcode-challenge/blob/master/src/day-two/index.ts) :expressionless:
6+
- Day 3: [Ransom Note](https://github.com/libterty/leetcode-challenge/blob/master/src/day-three/index.ts) :hushed:
7+
- Day 4: [Number Complement](https://github.com/libterty/leetcode-challenge/blob/master/src/day-four/index.ts) :laughing:

src/day-four/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @param {number} num
3+
* @return {number}
4+
*/
5+
export const findComplement = function (num: number): number {
6+
let inputStr: string[] = num.toString(2).split('');
7+
let outputStr: string = '';
8+
9+
inputStr.forEach((n: string): string => (n === '1' ? (outputStr += '0') : (outputStr += '1')));
10+
11+
return parseInt(outputStr, 2);
12+
};
13+
14+
const data = findComplement(5);
15+
console.log('data', data);

0 commit comments

Comments
 (0)