File tree 2 files changed +19
-3
lines changed 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change 1
1
# LeetCode Challenge
2
2
3
3
- 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 :
Original file line number Diff line number Diff line change
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 ) ;
You can’t perform that action at this time.
0 commit comments