Skip to content

Commit 9b037e3

Browse files
committed
Solution for 476.
1 parent 7f15791 commit 9b037e3

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

solution/0400-0499/0476.Number Complement/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ class Solution:
7272
return ans
7373
```
7474

75+
```python
76+
class Solution:
77+
def findComplement(self, num: int) -> int:
78+
return num ^ (2 ** (len(bin(num)[2:])) - 1)
79+
80+
```
81+
7582
### **Java**
7683

7784
<!-- 这里可写当前语言的特殊实现逻辑 -->

solution/0400-0499/0476.Number Complement/README_EN.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ class Solution:
6060
return ans
6161
```
6262

63+
```python
64+
class Solution:
65+
def findComplement(self, num: int) -> int:
66+
return num ^ (2 ** (len(bin(num)[2:])) - 1)
67+
68+
```
69+
6370
### **Java**
6471

6572
```java
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Solution:
2+
def findComplement(self, num: int) -> int:
3+
return num ^ (2 ** (len(bin(num)[2:])) - 1)

0 commit comments

Comments
 (0)