Skip to content

Commit 3b8301e

Browse files
🎨 Day 5
1 parent 0da77c6 commit 3b8301e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
2. [Combination Sum](https://leetcode.com/explore/challenge/card/october-leetcoding-challenge/559/week-1-october-1st-october-7th/3481/) ➡️ [CPP Solution](Week1/combinationSum.cpp)
1111
3. [K-diff Pairs in an Array](https://leetcode.com/explore/challenge/card/october-leetcoding-challenge/559/week-1-october-1st-october-7th/3482/) ➡️ [CPP Solution](Week1/findPairs.cpp)
1212
4. [Remove Covered Intervals](https://leetcode.com/explore/challenge/card/october-leetcoding-challenge/559/week-1-october-1st-october-7th/3482/) ➡️ [CPP Solution](Week1/removeCoveredIntervals.cpp)
13+
5. [Complement of Base 10 Integer](https://leetcode.com/explore/challenge/card/october-leetcoding-challenge/559/week-1-october-1st-october-7th/3482/) ➡️ [CPP Solution](Week1/bitwiseComplement.cpp)
1314

1415
## Week 2 🚧
1516

Week1/bitwiseComplement.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
int bitwiseComplement(int N) {
4+
if(N == 0) return 1;
5+
6+
int bits = 0;
7+
int tmp = N;
8+
9+
while(tmp > 0) {
10+
tmp >>= 1;
11+
bits++;
12+
}
13+
14+
int maxNumberWithSameSetBits = pow(2, bits) - 1;
15+
16+
return N ^ maxWithSameBits;
17+
}
18+
};

0 commit comments

Comments
 (0)