```python
[Read More]
LC717. 1-bit and 2-bit Characters
```python class Solution: def isOneBitCharacter(self, bits: List[int]) -> bool: “"”tc O(N) sc(N) “”” start = 0 end = len(bits) -1 def dfs(s,e): if s > e : return True if bits[s] == 0: return True and dfs(s+1,e) elif e-s >1 and bits[s] == 1: return True and dfs(s+2,e) return False...
[Read More]
LC568. Maximum Vacation Days
```python class Solution: def maxVacationDays(self, flights: List[List[int]], days: List[List[int]]) -> int: “”” tc O(KNN) sc O(NK) 1. dp(i,j): start from week j unti Kth week, fly off from city i, how many vocation days can take the most 2. exist case(base case): week >= K 3. state transition fomular: max_days...
[Read More]
LC606. Construct String from Binary Tree
```python
“””
tc O(N) sc O(N)
stack store id, each time get a ‘start’ log, update its previous id’s acuumutive time
each time get a ‘end’ log, pop off cached id since the job has ended; and update ended job’s accumutive time
[Read More]
LC636. Exclusive Time of Functions
```python Definition for a binary tree node. class TreeNode: def init(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right class Solution: def tree2str(self, t: TreeNode) -> str: “”” tc O(N) sc O(N) 1. 4 cases: (1)both left right child (2)no children (3) has only left child...
[Read More]