LC124 Binary Tree Maximum Path Sum

# 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: # main idea: do post order traversal and caculate current case1,2,3 max path and keep updating it # case 1:... [Read More]
Tags: Tree DFS

LC105 Construct Binary Tree from Preorder and Inorder Traversal

link # 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 buildTree(self, preorder: List[int], inorder: List[int]) -> TreeNode: """tc O(N) sc O(1) main idea: (recursion) for each subtree there... [Read More]
Tags: Tree DFS Array

Lc557

```python class Solution: #time O(N) space(1) def reverseWords(self, s: str) -> str: s = s.split(‘ ‘) for idx, each in enumerate(l): s[idx] = each[::-1] [Read More]

Lc1443

```python class Solution: def minTime(self, n: int, edges: List[List[int]], hasApple: List[bool]) -> int: # step1 , build bi-directional tree, create map with linked list to represent child nodes / edges self.tree = collections.defaultdict(list) self.visited = set() for parent, child in edges: if child in self.tree[0]: # make sure if given... [Read More]