Skip to content

Commit 757e1f2

Browse files
authored
Merge pull request #1 from ATRI2107/bfs
Bfs
2 parents bbad7a2 + 2be421f commit 757e1f2

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

Java/number-complement.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public int findComplement(int num) {
3+
4+
int numberOfBits = numberOfBits(num);
5+
6+
return num ^ ((1 << numberOfBits) - 1);
7+
}
8+
9+
/**
10+
* Method to find out the total number of bits in a number.
11+
**/
12+
public static int numberOfBits(int num){
13+
int countOfBits = 0;
14+
15+
while(num != 0){
16+
num = num >> 1;
17+
countOfBits++;
18+
}
19+
20+
return countOfBits;
21+
}
22+
}

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,12 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu
6868

6969
# Bit Manipulation
7070

71-
| # | Title | Solution | Time | Space | Difficulty | Tag | Note |
71+
| # | Title | Solution | Time | Space | Difficulty | Tag | Tutorial |
7272
| ---- | --------------------------------------------------------------------- | -------------------------------------------------------------------------- | ------ | ------ | ---------- | --- | --------- |
7373
| 0136 | [Single Number](https://leetcode.com/problems/single-number/) | [Java](./Java/single-number.java) <br> [Python](./Python/single-number.py) <br> [C++](./C++/Single-Number.cpp) | _O(n)_ | _O(1)_ | Easy | | Using XOR |
74-
| 0260 | [Single Number III](https://leetcode.com/problems/single-number-iii/) | [Python](./Python/single-number-iii.py) | _O(n)_ | _O(1)_ | Medium | | |
75-
| 0520 | [Detect Capital Use](https://leetcode.com/problems/detect-capital/) | [Python](./Python/detect-capital.py) | _O(n)_ | _O(1)_ | Easy | | |
74+
| 260 | [Single Number III](https://leetcode.com/problems/single-number-iii/) | [Python](./Python/single-number-iii.py) | _O(n)_ | _O(1)_ | Medium | | |
75+
| 476 | [Number Complement](https://leetcode.com/problems/number-complement/) | [Java](./Java/number-complement.java) | _O(1)_ | _O(1)_ | Easy | | |
76+
| 520 | [Detect Capital Use](https://leetcode.com/problems/detect-capital/) | [Python](./Python/detect-capital.py) | _O(n)_ | _O(1)_ | Easy | | |
7677

7778
<br/>
7879
<div align="right">
@@ -358,7 +359,7 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if
358359

359360
## Authors
360361

361-
- [Gourav Rusiya](https://github.com/GouravRusiya30/)
362+
- | [Gourav Rusiya](https://github.com/GouravRusiya30/) <br> <img src="https://github.com/GouravRusiya30.png" width="100" height="100">
362363

363364
<br>
364365

0 commit comments

Comments
 (0)