↓Skip to main content

Array

LeetCode 747: Largest Number At Least Twice of Others
·2 mins
LeetCode Easy Array Sorting
LeetCode 747 note: find the largest and second largest in one pass and return the largest’s index if it is at least twice the second; multiply to avoid dividing by zero
LeetCode 744: Find Smallest Letter Greater Than Target
·1 min
LeetCode Easy Array Binary-Search
LeetCode 744 note: find the first letter > target (an upper bound), wrapping around to the first letter if none exists
LeetCode 733: Flood Fill
·2 mins
LeetCode Easy Array Depth-First-Search Breadth-First-Search Matrix
LeetCode 733 note: DFS or BFS from the start, recoloring 4-directional cells that share the start’s original color; return immediately if the colors are equal
LeetCode 705: Design HashSet
·2 mins
LeetCode Easy Array Hash-Table Linked-List Design
LeetCode 705 note: a fixed number of buckets, with the key modulo the bucket count choosing the bucket and a list per bucket handling collisions
LeetCode 704: Binary Search
·2 mins
LeetCode Easy Array Binary-Search
LeetCode 704 note: a closed interval [l, r] with an integer mid; return on a match, otherwise discard the half that cannot contain the target
LeetCode 697: Degree of an Array
·2 mins
LeetCode Easy Array Hash-Table
LeetCode 697 note: record each value’s count, first index and last index; among the most frequent values, take the shortest span
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 674: Longest Continuous Increasing Subsequence
·2 mins
LeetCode Easy Array
LeetCode 674 note: one pass that extends the run while strictly increasing and resets to 1 otherwise, updating the maximum after the loop too
LeetCode 661: Image Smoother
·2 mins
LeetCode Easy Array Matrix
LeetCode 661 note: each cell becomes the floored average of the existing cells in its 3 × 3 neighborhood, written into a new matrix
LeetCode 645: Set Mismatch
·2 mins
LeetCode Easy Array Hash-Table Bit-Manipulation Sorting
LeetCode 645 note: use sums: missing = sum of 1..n - sum of the set, duplicate = array sum - sum of the set
LeetCode 628: Maximum Product of Three Numbers
·1 min
LeetCode Easy Array Math Sorting
LeetCode 628 note: after sorting there are only two candidates: the three largest, or the two smallest (negatives) times the largest
LeetCode 605: Can Place Flowers
·2 mins
LeetCode Easy Array Greedy
LeetCode 605 note: scan left to right and plant in any empty plot whose neighbors are empty; a new flower blocks the next plot, so actually update the array