-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b119987
commit f6fef11
Showing
1 changed file
with
11 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,20 @@ | ||
# [Problem 476: Number Complement](https://leetcode.com/problems/number-complement/description/?envType=daily-question) | ||
|
||
## Initial thoughts (stream-of-consciousness) | ||
- This one is trivial-- there are built-in functions that can help | ||
|
||
## Refining the problem, round 2 thoughts | ||
- We just need to return `int(bin(num)[2:].replace('0', 'x').replace('1', '0').replace('x', '1'), 2)` | ||
|
||
## Attempted solution(s) | ||
```python | ||
class Solution: # paste your code here! | ||
... | ||
class Solution: | ||
def findComplement(self, num: int) -> int: | ||
return int(bin(num)[2:].replace('0', 'x').replace('1', '0').replace('x', '1'), 2) | ||
``` | ||
- Given test cases pass | ||
- Submitting... | ||
|
||
![Screenshot 2024-08-21 at 8 08 15 PM](https://github.com/user-attachments/assets/0c32eac5-1704-46af-9ca3-24a00928b7ef) | ||
|
||
Solved! |