Dynamic-Programming
LeetCode 264: Ugly Number II
·2 mins
LeetCode
Medium
Hash-Table
Math
Dynamic-Programming
Heap-Priority-Queue
LeetCode 264 note: three pointers mark the next ugly numbers to multiply by 2, 3 and 5; take the minimum each time and advance every pointer that produced it
LeetCode 647: Palindromic Substrings
·2 mins
LeetCode
Medium
Two-Pointers
String
Dynamic-Programming
LeetCode 647 note: expand around centers, counting one palindromic substring for each successful expansion
LeetCode 131: Palindrome Partitioning
·2 mins
LeetCode
Medium
String
Dynamic-Programming
Backtracking
LeetCode 131 note: each level cuts a palindrome from the front of the remaining string, trying every length from 1 to the whole remainder
LeetCode 42: Trapping Rain Water
·2 mins
LeetCode
Hard
Array
Two-Pointers
Dynamic-Programming
Stack
LeetCode 42 note: each cell holds min(tallest on the left, tallest on the right) - its own height; use prefix and suffix maxima or two pointers
LeetCode 5: Longest Palindromic Substring
·2 mins
LeetCode
Medium
Two-Pointers
String
Dynamic-Programming
Manacher
LeetCode 5 note: expand around centers, using each position as an odd and an even center; with interval DP, iterate i from large to small
LeetCode 1137: N-th Tribonacci Number
·2 mins
LeetCode
Easy
Math
Dynamic-Programming
Memoization
LeetCode 1137 note: like Fibonacci, roll three variables; watch the base values T0 = 0, T1 = T2 = 1 and the loop range
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 509: Fibonacci Number
·1 min
LeetCode
Easy
Math
Dynamic-Programming
Recursion
Memoization
LeetCode 509 note: the starting point of 1D DP; only the previous two terms are needed, so roll two variables
LeetCode 392: Is Subsequence
·2 mins
LeetCode
Easy
Two-Pointers
String
Dynamic-Programming
LeetCode 392 note: two pointers; the pointer on t always advances, and the one on s advances on a match; bound-check both
LeetCode 119: Pascal's Triangle II
·2 mins
LeetCode
Easy
Array
Dynamic-Programming
LeetCode 119 note: only row rowIndex is needed; update a 1D array from right to left for O(k) space
LeetCode 118: Pascal's Triangle
·1 min
LeetCode
Easy
Array
Dynamic-Programming
LeetCode 118 note: each row starts and ends with 1, and every inner cell is the sum of the two cells above it