use bit addition class Solution: def bitwiseComplement(self, N: int) -> int: # time O(lgN) space O(1) # N + complement(N) = 11111 = X x = 1 while N > x: x = x *2 +1 return x - N use ^ class Solution: def bitwiseComplement(self, N: int) -> int:...
[Read More]
1288 Remove Covered Intervals
only sort by start solution ```python class Solution: def removeCoveredIntervals(self, intervals: List[List[int]]) -> int: “”” main idea:determine condition: l<s and r < e. note the left,rightbound; “”” cnt,l,r = 0,-1,-1 intervals.sort(key = lambda t: t[0]) for s, e in intervals: if e>r and s>l : cnt += 1 l =...
[Read More]
LC532 K-diff Pairs in an Array
```python class Solution: def findPairs(self, nums: List[int], k: int) -> int: “”” to avoid duplicate, use map to record the occurance of each unique number. case1: k > 0 instead of loop through each unique number to check match for current number, use map to directly check if cur_num +...
[Read More]
933. Number of Recent Calls
```python
# time&space O(min(N,K)) K: 3000
class RecentCounter:
[Read More]
LC28 Implement strStr()
```python
[Read More]