Depth-First-Search
LeetCode 965: Univalued Binary Tree
·1 min
LeetCode
Easy
Tree
Depth-First-Search
Breadth-First-Search
Binary-Tree
LeetCode 965 note: every value must equal the root’s; compare values while recursing, not the booleans the recursion returns
LeetCode 938: Range Sum of BST
·2 mins
LeetCode
Easy
Tree
Depth-First-Search
Binary-Search-Tree
Binary-Tree
LeetCode 938 note: prune with the BST order, going only right below low and only left above high, adding nodes inside the range
LeetCode 897: Increasing Order Search Tree
·1 min
LeetCode
Easy
Stack
Tree
Depth-First-Search
Binary-Search-Tree
LeetCode 897 note: in-order traversal appending nodes to a right-only chain with left children cleared; keep the dummy separate from the moving tail
LeetCode 872: Leaf-Similar Trees
·1 min
LeetCode
Easy
Tree
Depth-First-Search
Binary-Tree
LeetCode 872 note: collect leaves left to right with DFS; BFS collects level by level, which is not left-to-right order
LeetCode 783: Minimum Distance Between BST Nodes
·2 mins
LeetCode
Easy
Tree
Depth-First-Search
Breadth-First-Search
Binary-Search-Tree
LeetCode 783 note: a BST’s in-order is ascending, so the minimum difference is between in-order neighbors; remember the previous value and compare
LeetCode 733: Flood Fill
·2 mins
LeetCode
Easy
Array
Depth-First-Search
Breadth-First-Search
Matrix
LeetCode 733 note: DFS or BFS from the start, recoloring 4-directional cells that share the start’s original color; return immediately if the colors are equal
LeetCode 671: Second Minimum Node In a Binary Tree
·2 mins
LeetCode
Easy
Tree
Depth-First-Search
Binary-Tree
LeetCode 671 note: the root is the minimum; the second minimum is the smallest value larger than the root, and only subtrees equal to the root need searching
LeetCode 653: Two Sum IV - Input is a BST
·2 mins
LeetCode
Easy
Hash-Table
Two-Pointers
Tree
Depth-First-Search
LeetCode 653 note: traverse while keeping a set of seen values; finding k - val in it means a pair exists
LeetCode 637: Average of Levels in Binary Tree
·1 min
LeetCode
Easy
Tree
Depth-First-Search
Breadth-First-Search
Binary-Tree
LeetCode 637 note: level-order traversal, dividing each level’s sum by its count
LeetCode 606: Construct String from Binary Tree
·1 min
LeetCode
Medium
String
Tree
Depth-First-Search
Binary-Tree
LeetCode 606 note: output in pre-order, keeping an empty () when only the left subtree is missing, and omitting the right parentheses when it is empty
LeetCode 590: N-ary Tree Postorder Traversal
·1 min
LeetCode
Easy
Stack
Tree
Depth-First-Search
LeetCode 590 note: post-order is each child then the node; iteratively, run a root-then-children-right-to-left pre-order and reverse the whole result
LeetCode 589: N-ary Tree Preorder Traversal
·2 mins
LeetCode
Easy
Stack
Tree
Depth-First-Search
LeetCode 589 note: n-ary pre-order records the node then each child in order; flatten recursive results with extend, not by appending a list