LeetCode
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
LeetCode 575: Distribute Candies
·1 min
LeetCode
Easy
Array
Hash-Table
LeetCode 575 note: at most n / 2 candies can be eaten and at most len(set) kinds exist; the answer is the smaller of the two
LeetCode 572: Subtree of Another Tree
·2 mins
LeetCode
Easy
Tree
Depth-First-Search
String-Matching
Binary-Tree
LeetCode 572 note: for every node of root, check whether its subtree equals subRoot; recurse with isSubtree, not by comparing only the children
LeetCode 566: Reshape the Matrix
·2 mins
LeetCode
Easy
Array
Matrix
Simulation
LeetCode 566 note: return the original if the element counts differ; otherwise element k goes to (k // c, k % c)
LeetCode 563: Binary Tree Tilt
·1 min
LeetCode
Easy
Tree
Depth-First-Search
Binary-Tree
Dp-on-Trees
LeetCode 563 note: return subtree sums in post-order; each node’s tilt is the difference of its subtree sums, added to the answer
LeetCode 561: Array Partition
·1 min
LeetCode
Easy
Array
Greedy
Sorting
Counting-Sort
LeetCode 561 note: sort and pair neighbors; each pair’s minimum is the element at an even index, so sum those
LeetCode 559: Maximum Depth of N-ary Tree
·1 min
LeetCode
Easy
Tree
Depth-First-Search
Breadth-First-Search
LeetCode 559 note: depth is 1 plus the deepest child, or 1 with no children
LeetCode 557: Reverse Words in a String III
·1 min
LeetCode
Easy
Two-Pointers
String
LeetCode 557 note: split on spaces, reverse each word, and join with spaces
LeetCode 551: Student Attendance Record I
·1 min
LeetCode
Easy
String
LeetCode 551 note: fewer than two A’s and no LLL substring
LeetCode 543: Diameter of Binary Tree
·2 mins
LeetCode
Easy
Tree
Depth-First-Search
Binary-Tree
Dp-on-Trees
LeetCode 543 note: the diameter may skip the root; return heights in post-order while updating the answer with left + right height at every node, counting edges
LeetCode 541: Reverse String II
·1 min
LeetCode
Easy
Two-Pointers
String
LeetCode 541 note: in every block of 2k reverse the first k; when fewer than k remain reverse them all, which slicing handles automatically