LeetCode
LeetCode 75: Sort Colors
·2 mins
LeetCode
Medium
Array
Two-Pointers
Sorting
Quicksort
LeetCode 75 note: the Dutch flag, with 0s left of low and 2s right of high; after swapping a 2 to high, do not advance, since the swapped-in value is unchecked
LeetCode 74: Search a 2D Matrix
·2 mins
LeetCode
Medium
Array
Binary-Search
Matrix
LeetCode 74 note: each row continues the previous one in sorted order, so binary search it as a 1-D array of length m × n, mapping mid to (mid // n, mid % n)
LeetCode 73: Set Matrix Zeroes
·2 mins
LeetCode
Medium
Array
Hash-Table
Matrix
LeetCode 73 note: record which rows and columns contain a 0 first, then update afterward; the follow-up uses the first row and column as markers
LeetCode 71: Simplify Path
·2 mins
LeetCode
Medium
String
Stack
LeetCode 71 note: split on /, skip empty pieces and ., pop on .. (never above root), push other names, and join with /
LeetCode 61: Rotate List
·1 min
LeetCode
Medium
Linked-List
Two-Pointers
LeetCode 61 note: count the length and close a ring, take k %= n, walk n - k - 1 steps from the head to the new tail, and break there
LeetCode 59: Spiral Matrix II
·2 mins
LeetCode
Medium
Array
Matrix
Simulation
LeetCode 59 note: keep four boundaries as in LC 54, but fill in 1 to n² instead of reading
LeetCode 57: Insert Interval
·2 mins
LeetCode
Medium
Array
LeetCode 57 note: split the intervals into three groups, entirely left, entirely right and overlapping, and merge the overlapping ones into one
LeetCode 56: Merge Intervals
·2 mins
LeetCode
Medium
Array
Sorting
Quicksort
LeetCode 56 note: sort by start; if a new interval starts at or before the last merged end, merge (taking the max end), otherwise open a new one
LeetCode 54: Spiral Matrix
·2 mins
LeetCode
Medium
Array
Matrix
Simulation
LeetCode 54 note: keep four boundaries and walk right, down, left and up, shrinking a boundary after each side
LeetCode 49: Group Anagrams
·2 mins
LeetCode
Medium
Array
Hash-Table
String
Sorting
LeetCode 49 note: use each string’s sorted form as a key; strings sharing a key form one anagram group
LeetCode 47: Permutations II
·2 mins
LeetCode
Medium
Array
Backtracking
Sorting
LeetCode 47 note: sort first, and within a level skip a value equal to the previous one when the previous one is unused
LeetCode 46: Permutations
·2 mins
LeetCode
Medium
Array
Backtracking
LeetCode 46 note: each level picks one unused number, marked in a used array, and records when the path is full