LeetCode
LeetCode 876: Middle of the Linked List
·2 mins
LeetCode
Easy
Linked-List
Two-Pointers
LeetCode 876 note: fast moves two steps and slow one; when fast reaches the end slow is in the middle, the right-middle for even lengths
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 868: Binary Gap
·2 mins
LeetCode
Easy
Bit-Manipulation
LeetCode 868 note: remember the last 1’s position and take the maximum distance at each new 1
LeetCode 867: Transpose Matrix
·1 min
LeetCode
Easy
Array
Matrix
Simulation
LeetCode 867 note: the transpose is n × m with res[j][i] = matrix[i][j]; in Python, zip(*matrix)
LeetCode 860: Lemonade Change
·2 mins
LeetCode
Easy
Array
Greedy
LeetCode 860 note: track only the counts of $5 and $10 bills; for $15 change prefer 10 + 5, since $5 bills are more versatile
LeetCode 859: Buddy Strings
·2 mins
LeetCode
Easy
Hash-Table
String
LeetCode 859 note: lengths must match; identical strings need a repeated character; otherwise exactly two positions differ and cross-match
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 836: Rectangle Overlap
·2 mins
LeetCode
Easy
Math
Geometry
LeetCode 836 note: two rectangles overlap exactly when their x intervals and y intervals both overlap, i.e. min(right) > max(left)
LeetCode 832: Flipping an Image
·2 mins
LeetCode
Easy
Array
Two-Pointers
Bit-Manipulation
Matrix
LeetCode 832 note: reverse each row and invert its bits, which two pointers can do at once
LeetCode 824: Goat Latin
·1 min
LeetCode
Easy
String
LeetCode 824 note: split into words and convert each: move a leading consonant to the end, then append ma and i + 1 copies of a
LeetCode 821: Shortest Distance to a Character
·2 mins
LeetCode
Easy
Array
Two-Pointers
String
LeetCode 821 note: one left-to-right pass for the distance to the nearest c on the left, then a right-to-left pass taking the minimum
LeetCode 819: Most Common Word
·2 mins
LeetCode
Easy
Array
Hash-Table
String
Counting
LeetCode 819 note: replace punctuation with spaces, lowercase, split, count, and pick the most frequent word not banned