821. Shortest Distance to a Character
```python class Solution: def shortestToChar(self, S: str, C: str) -> List[int]: # time O(N) space O(N) #[3, 2, 1, 0, 1, 0, 0, 1, 2, 2, 1, 0] el length = len(S) res = [length]*length # r e l loop l = 0 r = length- 1 el = None...
[Read More]
545. Boundary of Binary Tree
```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: # time O(N) space O(N) def boundaryOfBinaryTree(self, root: TreeNode) -> List[int]: # order root=> left boundry ==> leaf nodes (not include leaf nodes) ==> right...
[Read More]
991. Broken Calculator
main idea: if Y is odd, the last number to be reached before Y is Y+1 (optimal path); if Y is even, the last number to be reached before Y is Y//2 (optimal path)
[Read More]
764. Largest Plus Sign
```python class Solution: def orderOfLargestPlusSign(self, N: int, mines: List[List[int]]) -> int: # step1 first build grid grid = [[N]*N for _ in range(N) ] for m in mines: grid[m[0]][m[1]] = 0 # step 2 l,r,u,d check # grid[i][j]: fartherest distance, start from (i,j) l,r,u,d can go for i in range(N):...
[Read More]