You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*[Time and Space Complexity of Algorithms](#complexity-of-an-algorithm-chart_with_upwards_trend)
35
35
*[How to Approach a Coding Question](#how-to-approach-a-coding-question-heavy_check_mark)
@@ -156,7 +156,7 @@ space, where `w` is the maximum width of a tree. Moreover, it is very important
156
156
[437](https://leetcode.com/problems/path-sum-iii/) | Path Sum III | Easy/Medium | [113](https://leetcode.com/problems/path-sum-ii/), [129](https://leetcode.com/problems/sum-root-to-leaf-numbers/), [257](https://leetcode.com/problems/binary-tree-paths/) | For Problem 437, use hash_table + DFS to achieve linear time complexity, similar to two sum problem. Check out similar problem [560](https://leetcode.com/problems/subarray-sum-equals-k/).
157
157
[124](https://leetcode.com/problems/binary-tree-maximum-path-sum/) | Binary Tree Maximum Path Sum | Hard/Medium | [543](https://leetcode.com/problems/diameter-of-binary-tree/) | Find left sum and right sum, and use both of them to calculate the sum with the current node as the root, and return only one of them.
158
158
[572](https://leetcode.com/problems/subtree-of-another-tree/) | Subtree of Another Tree | Easy/Medium | [687](https://leetcode.com/problems/longest-univalue-path/) | Recursively check if `t` is the same tree with a tree rooted at the current node, or if `t` is a subtree rooted at current node's left or right child. Problem 687 can have linear time complexity by calculating the longest path by using left and right paths and only returning the max of left and right paths.
159
-
[102](https://leetcode.com/problems/binary-tree-level-order-traversal/) | Binary Tree Level Order Traversal | Medium | [637](https://leetcode.com/problems/average-of-levels-in-binary-tree/), [513](https://leetcode.com/problems/find-bottom-left-tree-value/), [429](https://leetcode.com/problems/n-ary-tree-level-order-traversal/), [1302](https://leetcode.com/problems/deepest-leaves-sum/), [872](https://leetcode.com/problems/leaf-similar-trees/) | Level-order traversal. Use BFS or `defaultdict[list]` to add node into corresponding level.
159
+
[102](https://leetcode.com/problems/binary-tree-level-order-traversal/) | Binary Tree Level Order Traversal | Medium | [637](https://leetcode.com/problems/average-of-levels-in-binary-tree/), [513](https://leetcode.com/problems/find-bottom-left-tree-value/), [429](https://leetcode.com/problems/n-ary-tree-level-order-traversal/), [1302](https://leetcode.com/problems/deepest-leaves-sum/) | Level-order traversal. Use BFS or `defaultdict[list]` to add node into corresponding level.
160
160
[144](https://leetcode.com/problems/binary-tree-preorder-traversal/) | Binary Tree Preorder Traversal | Medium | [589](https://leetcode.com/problems/n-ary-tree-preorder-traversal/), [145](https://leetcode.com/problems/binary-tree-postorder-traversal/), [590](https://leetcode.com/problems/n-ary-tree-postorder-traversal/), [94](https://leetcode.com/problems/binary-tree-inorder-traversal/) | Recursively is trivial, but iteratively is very complicated. IMO, iteratively in-order traversal is the hardest.
161
161
[297](https://leetcode.com/problems/serialize-and-deserialize-binary-tree/) | Serialize and Deserialize Binary Tree | Hard | [449](https://leetcode.com/problems/serialize-and-deserialize-bst/), [1008](https://leetcode.com/problems/construct-binary-search-tree-from-preorder-traversal/), [106](https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/), [105](https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/) | In the binary tree problem, we need to have "null" indicator to represent null node in the serialized string, while BST does not. BST problem uses pre-order traversal to serialize and deserialize by recursively building trees by checking lower and upper bounds for subtrees.
162
162
[968](https://leetcode.com/problems/binary-tree-cameras/) | Binary Tree Cameras | Hard | [979](https://leetcode.com/problems/distribute-coins-in-binary-tree/) | Bottom up. DFS + greedy.
0 commit comments