```python
class TrieNode:
def init(self):
self.children = {}#self.children = collections.defaultdict(TrieNode)
self.isEnd = False
[Read More]
LC733 Flood Fill
```python class Solution: def floodFill(self, image: List[List[int]], sr: int, sc: int, newColor: int) -> List[List[int]]: # time O(N) space O(1) # main idea: step1: check if start point has the same color the recursion will never end; step2; dfs and set conditions to check 4 directions to avoid out of...
[Read More]
LC497 Random Point in Non-overlapping Rectangles
```python
class Solution:
[Read More]
LC905 Sort Array By Parity
class Solution: def sortArrayByParity(self, A: List[int]) -> List[int]: # time O(N) space O(N) # main idea: assign number to odd,even list seperately and link two lists together even = [] odd = [] for num in A: if num % 2 != 0: odd.append(num) else: even.append(num) even.extend(odd) return even optimization(in...
[Read More]
LC47 Permutaions II
class Solution: def permuteUnique(self, nums: List[int]) -> List[List[int]]: # time O(N!) space O(N) d = collections.Counter(nums) self.res = [] self._btrack(nums,d,[]) return self.res def _btrack(self,nums,counter,path ): if len(nums) == len(path): self.res.append(path[:]) for num in counter: # loop will not pick dupplication if counter[num] > 0: path.append(num) counter[num] -= 1 self._btrack(nums,counter,path) path.pop()...
[Read More]