Stack
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 844: Backspace String Compare
·2 mins
LeetCode
Easy
Two-Pointers
String
Stack
Simulation
LeetCode 844 note: simulate backspaces with a stack; for O(1) space, walk from the end and count how many characters each # skips
LeetCode 682: Baseball Game
·1 min
LeetCode
Easy
Array
Stack
Simulation
LeetCode 682 note: keep valid scores on a stack; C removes the last, D adds its double, and + adds the sum of the last two
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 234: Palindrome Linked List
·2 mins
LeetCode
Easy
Linked-List
Two-Pointers
Stack
Recursion
LeetCode 234 note: find the middle with fast and slow pointers, reverse the second half, and compare from both ends with O(1) extra space
LeetCode 232: Implement Queue using Stacks
·1 min
LeetCode
Easy
Stack
Design
Queue
LeetCode 232 note: two stacks, where in receives pushes and out is refilled from in only when empty, amortized O(1)
LeetCode 225: Implement Stack using Queues
·2 mins
LeetCode
Easy
Stack
Design
Queue
LeetCode 225 note: one queue suffices: after a push, rotate all earlier elements to the back so the new element sits at the front
LeetCode 145: Binary Tree Postorder Traversal
·2 mins
LeetCode
Easy
Stack
Tree
Depth-First-Search
Binary-Tree
LeetCode 145 note: iterative post-order pushes a node back with a visited flag on its first pop, then the right and left children; record it on the second pop
LeetCode 94: Binary Tree Inorder Traversal
·2 mins
LeetCode
Easy
Stack
Tree
Depth-First-Search
Binary-Tree
LeetCode 94 note: iterative in-order traversal, pushing nodes while going left, recording on pop, then turning to the right subtree
LeetCode 144: Binary Tree Preorder Traversal
·1 min
LeetCode
Easy
Stack
Tree
Depth-First-Search
Binary-Tree
LeetCode 144 note: iterative pre-order traversal records on pop and pushes the right child before the left so the left is handled first