↓Skip to main content

Easy

LeetCode 492: Construct the Rectangle
·2 mins
LeetCode Easy Math
LeetCode 492 note: search the width downward from √area; the first divisor of area gives the most square-like rectangle
LeetCode 485: Max Consecutive Ones
·1 min
LeetCode Easy Array
LeetCode 485 note: extend the current count on a 1, reset it on a 0, and keep the maximum
LeetCode 482: License Key Formatting
·2 mins
LeetCode Easy String
LeetCode 482 note: remove every dash and uppercase first, then cut groups of k from the end so only the first group may be shorter
LeetCode 476: Number Complement
·1 min
LeetCode Easy Bit-Manipulation
LeetCode 476 note: build an all-ones mask as long as num; num ^ mask is the complement
LeetCode 463: Island Perimeter
·2 mins
LeetCode Easy Array Depth-First-Search Breadth-First-Search Matrix
LeetCode 463 note: each land cell contributes 4 edges, minus 2 for each land neighbor above or to the left
LeetCode 461: Hamming Distance
·1 min
LeetCode Easy Bit-Manipulation
LeetCode 461 note: each 1 in x ^ y is a differing bit, so count the ones
LeetCode 459: Repeated Substring Pattern
·1 min
LeetCode Easy String String-Matching Z-Algorithm Knuth-Morris-Pratt-Algorithm
LeetCode 459 note: s is a repetition of a substring exactly when s occurs in s + s with its first and last characters removed
LeetCode 455: Assign Cookies
·2 mins
LeetCode Easy Array Two-Pointers Greedy Sorting
LeetCode 455 note: sort children and cookies, satisfying the least greedy child with the smallest cookie that suffices; each pointer walks once
LeetCode 448: Find All Numbers Disappeared in an Array
·1 min
LeetCode Easy Array Hash-Table
LeetCode 448 note: use the array itself as the hash table, marking nums[x - 1] negative for each x; positions still positive are the missing numbers
LeetCode 441: Arranging Coins
·1 min
LeetCode Easy Math Binary-Search
LeetCode 441 note: find the largest k with k(k + 1) / 2 <= n; when moving right write l = mid + 1 or the search gets stuck
LeetCode 434: Number of Segments in a String
·1 min
LeetCode Easy String
LeetCode 434 note: split() with no argument ignores extra spaces, so the number of pieces is the answer
LeetCode 415: Add Strings
·2 mins
LeetCode Easy Math String Simulation
LeetCode 415 note: add digit by digit from the ends with two pointers, tracking the carry, and append any leftover carry after the loop