LeetCode
LeetCode 1078: Occurrences After Bigram
·1 min
LeetCode
Easy
String
LeetCode 1078 note: split into words and check every three consecutive words, collecting the third when the first two match
LeetCode 1051: Height Checker
·1 min
LeetCode
Easy
Array
Sorting
Counting-Sort
Bubble-Sort
LeetCode 1051 note: sort and count the positions that differ from the original
LeetCode 1047: Remove All Adjacent Duplicates In String
·1 min
LeetCode
Easy
String
Stack
LeetCode 1047 note: if the stack top equals the current character both vanish, otherwise push it; after a removal the new top may cancel with the next character
LeetCode 1046: Last Stone Weight
·2 mins
LeetCode
Easy
Array
Heap-Priority-Queue
LeetCode 1046 note: from a max-heap (negated values) take the two heaviest each round, push back their difference if unequal, and return the last stone or 0
LeetCode 1030: Matrix Cells in Distance Order
·2 mins
LeetCode
Easy
Array
Math
Geometry
Sorting
LeetCode 1030 note: list every coordinate and sort by Manhattan distance to the center; return coordinates, not distances
LeetCode 997: Find the Town Judge
·2 mins
LeetCode
Easy
Array
Hash-Table
Graph
LeetCode 997 note: the judge is trusted by the other n - 1 people and trusts nobody, so in-degree minus out-degree equals n - 1
LeetCode 1025: Divisor Game
·2 mins
LeetCode
Easy
Math
Dynamic-Programming
Brainteaser
Game-Theory
LeetCode 1025 note: dp[i] holds when some divisor x of i makes dp[i - x] a loss; observing the pattern, the answer is simply whether n is even
LeetCode 1022: Sum of Root To Leaf Binary Numbers
·2 mins
LeetCode
Easy
Tree
Depth-First-Search
Binary-Tree
LeetCode 1022 note: on the way down double the current number and add the node’s bit, adding it to the total at a leaf
LeetCode 1021: Remove Outermost Parentheses
·1 min
LeetCode
Easy
String
Stack
Bracket-Sequences
LeetCode 1021 note: track depth instead of a stack; the ‘(’ raising depth from 0 to 1 and the ‘)’ lowering it from 1 to 0 are outermost, everything else stays
LeetCode 1018: Binary Prefix Divisible By 5
·1 min
LeetCode
Easy
Array
Bit-Manipulation
LeetCode 1018 note: each new bit turns the prefix into x = 2x + bit, so keep only x mod 5 and the number never grows
LeetCode 1013: Partition Array Into Three Parts With Equal Sum
·2 mins
LeetCode
Easy
Array
Greedy
LeetCode 1013 note: the total must be divisible by 3; accumulate from the left, cutting whenever the running sum hits total / 3, and succeed with at least 3 pieces
LeetCode 1005: Maximize Sum Of Array After K Negations
·1 min
LeetCode
Easy
Array
Greedy
Sorting
LeetCode 1005 note: negate the smallest value each time; once the smallest is positive, only the parity of the remaining count matters