My personal leetcode answers
This is a continually updated, open source project.
🎉🎉🎉 Finished 100 questions on 2018-05-28
🎉🎉🎉 Finished 150 questions on 2018-06-29
| Problem |
Solution |
Time |
Difficulty |
Tag |
Note |
| 202.happy-number |
cpp, python |
O(N) |
Easy |
|
|
| Problem |
Solution |
Time |
Difficulty |
Tag |
Note |
| 136.single-number |
cpp |
O(N) |
Easy |
|
|
| Problem |
Solution |
Time |
Difficulty |
Tag |
Note |
| 53.maximum-subarray |
python |
O(N) |
Easy |
|
|
| 88.merge-sorted-array |
python |
O(N + M) |
Easy |
|
|
| 240.search-a-2d-matrix-ii |
cpp, python |
O(N + M) |
Medium |
|
|
| 349.intersection-of-two-arrays |
python |
O(N + M) |
Easy |
|
|
| 350.intersection-of-two-arrays-ii |
python |
O(N * logN) |
Easy |
|
|
| 560.subarray-sum-equals-k |
python |
O(N) |
Medium |
|
|
| Problem |
Solution |
Time |
Difficulty |
Tag |
Note |
| 796.rotate-string |
cpp, python |
O(N^2) |
Easy |
TODO: Rabin-Karp Algorithm, KMP algorithm |
|
| 859.buddy-strings |
cpp |
O(N) |
Easy |
|
|
| Problem |
Solution |
Time |
Difficulty |
Tag |
Note |
| 15.3sum |
cpp, python |
O(N^2) |
Medium |
|
|
| 16.3sum-closest |
cpp, python |
O(N^2) |
Medium |
|
|
| 18.4sum |
cpp, python |
O(N^3) |
Medium |
|
|
| 19.remove-nth-node-from-end-of-list |
cpp, python |
O(N) |
Medium |
|
|
| 75.sort-colors |
python |
O(N) |
Medium |
|
|
| 76.minimum-window-substring |
cpp |
O(N) |
Hard |
|
|
| 125.valid-palindrome |
python |
O(N) |
Easy |
|
|
| 141.linked-list-cycle |
python |
O(N) |
Easy |
linked-list |
|
| 142.linked-list-cycle-ii |
python |
O(N) |
Medium |
linked-list |
|
| 160.intersection-of-two-linked-lists |
python |
O(N + M) |
Easy |
linked-list |
|
| 167.two-sum-ii-input-array-is-sorted |
python |
O(N) |
Easy |
|
|
| 209.minimum-size-subarray-sum |
cpp |
O(N) / O(N * logN) |
Medium |
subarray |
|
| 283.move-zeroes |
python |
O(N) |
Easy |
|
|
| Problem |
Solution |
Time |
Difficulty |
Tag |
Note |
| 21.merge-two-sorted-lists |
cpp, python |
O(N) |
Easy |
|
|
| 25.reverse-nodes-in-k-group |
python |
O(N) |
Hard |
|
|
| 61.rotate-list |
python |
O(N) |
Medium |
|
|
| 86.partition-list |
python |
O(N) |
Medium |
|
|
| 92.reverse-linked-list-ii |
python |
O(N) |
Medium |
|
|
| 138.copy-list-with-random-pointer |
python |
O(N) |
Medium |
|
|
| 143.reorder-list |
python |
O(N) |
Medium |
|
|
| 148.sort-list |
python |
O(N * logN) |
Medium |
|
|
| 203.remove-linked-list-elements |
python |
O(N) |
Easy |
|
|
| 206.reverse-linked-list |
python |
O(N) |
Easy |
|
|
| 237.delete-node-in-a-linked-list |
python |
O(1) |
Easy |
|
|
| 328.odd-even-linked-list |
python |
O(N) |
Medium |
|
|
| Problem |
Solution |
Time |
Difficulty |
Tag |
Note |
| 33.search-in-rotated-sorted-array |
cpp |
O(logN) |
Medium |
TODO: Later |
|
| 34.search-for-a-range |
cpp |
Medium |
|
|
|
| 74.search-a-2d-matrix |
cpp, python |
O(logN) |
Medium |
N = row * column |
|
| 81.search-in-rotated-sorted-array-ii |
cpp |
O(logN) ~ O(N) |
Medium |
TODO: Later |
|
| 153.find-minimum-in-rotated-sorted-array |
cpp, python |
O(logN) |
Medium |
|
|
| 154.find-minimum-in-rotated-sorted-array-ii |
cpp, python |
O(logN) ~ O(N) |
Hard |
|
|
| 162.find-peak-element |
cpp |
O(logN) |
Meidum |
|
|
| 278.first-bad-version |
cpp, python |
O(logN) |
Easy |
|
|
| 302.smallest-rectangle-enclosing-black-pixels |
cpp |
O(M * N) / O(N * LogN) |
Hard |
|
|
| Problem |
Solution |
Time |
Difficulty |
Tag |
Note |
| 4.median-of-two-sorted-arrays |
cpp, python |
O(log(M + N)) |
Hard |
|
|
| 98.validate-binary-search-tree |
cpp, python |
O(N) |
Medium |
|
TODO: inorder-traversal |
| 104.maximum-depth-of-binary-tree |
cpp, python |
O(N) |
Easy |
|
|
| 110.balanced-binary-tree |
cpp, python |
O(N) |
Easy |
|
|
| 215.kth-largest-element-in-an-array |
python |
O(N) ~ O(N^2) |
Medium |
quick-select |
|
| 236.lowest-common-ancestor-of-a-binary-tree |
cpp, python |
O(N) |
Medium |
|
|
| Problem |
Solution |
Time |
Difficulty |
Tag |
Note |
| 102.binary-tree-level-order-traversal |
cpp |
O(N) |
Medium |
|
|
| 107.binary-tree-level-order-traversal-ii |
cpp |
O(N) |
Easy |
|
|
| Problem |
Solution |
Time |
Difficulty |
Tag |
Note |
| 127.word-ladder |
python |
O(N * L^2) |
Medium |
BFS |
|
| 200.number-of-islands |
python |
O(M x N) |
Medium |
BFS/DFS |
union-find |
| 207.course-schedule |
cpp |
O(V + E) |
Medium |
|
|
| 210.course-schedule-ii |
cpp |
O(V + E) |
Medium |
topological-sort |
|
| 444.sequence-reconstruction |
cpp, python |
O(V+E) |
Medium |
topological-sort |
|
| Problem |
Solution |
Time |
Difficulty |
Tag |
Note |
| 39.combination-sum |
python |
??? |
Medium |
DFS |
|
| 40.combination-sum-ii |
python |
??? |
Medium |
DFS |
|
| 46.permutations |
python |
??? |
Medium |
DFS |
|
| 47.permutations-ii |
python |
??? |
Medium |
DFS |
|
| 51.n-queens |
python |
??? |
Hard |
DFS |
|
| 52.n-queens-ii |
python |
??? |
Hard |
DFS |
|
| 78.subsets |
cpp, python |
O(N * 2^N) |
Medium |
DFS |
bit-manipulation / iterative |
| 90.subsets-ii |
cpp, python |
O(N * 2^N) |
Medium |
DFS |
bit-manipulation |
| 126.word-ladder-ii |
python |
O((V+E) * L^2) |
Hard |
BFS+DFS |
|
| 131.palindrome-partitioning |
python |
??? |
Medium |
DFS |
|
| Problem |
Solution |
Time |
Difficulty |
Tag |
Note |
| 1.two-sum |
cpp, python |
O(N) |
Easy |
|
|
| 3.longest-substring-without-repeating-characters |
cpp, python |
O(N) |
Medium |
|
|
| 36.valid-sudoku |
cpp |
O(N ^ 2) |
Medium |
array-indexes |
|
| 49.group-anagrams |
cpp |
O(N * k * Logk) |
Medium |
|
|
| 170.two-sum-iii-data-structure-design |
cpp, python |
O(N) |
Easy |
|
|
| 202.happy-number |
cpp, python |
O(N) |
Easy |
|
|
| 205.isomorphic-strings |
cpp, python |
O(N) |
Easy |
|
|
| 217.contains-duplicate |
cpp |
O(N) |
Easy |
|
|
| 219.contains-duplicate-ii |
cpp |
O(N) |
Easy |
|
|
| 249.group-shifted-strings |
cpp |
O(N * K) |
Medium |
|
|
| 288.unique-word-abbreviation |
cpp |
- |
Medium |
|
|
| 347.top-k-frequent-elements |
cpp |
O(N * LogN) |
Medium |
TODO: quick-sort, bucket-sort |
|
| 349.intersection-of-two-arrays |
cpp |
O(M + N) |
Easy |
|
|
| 350.intersection-of-two-arrays-ii |
cpp |
O(M * N) |
Easy |
|
|
| 359.logger-rate-limiter |
cpp |
O(1) |
Easy |
amortized |
|
| 380.insert-delete-getrandom-o1 |
cpp |
O(1) |
Medium |
|
|
| 454.4sum-ii |
cpp |
O(N ^ 2) |
Medium |
|
|
| 599.minimum-index-sum-of-two-lists |
cpp |
O(M + N) |
Easy |
|
|
| 652.find-duplicate-subtrees |
cpp |
O(N) |
Medium |
|
|
| 771.jewels-and-stones |
cpp |
O(M + N) |
Easy |
|
|
| Problem |
Solution |
Time |
Difficulty |
Tag |
Note |
| 23.merge-k-sorted-lists |
cpp |
O(N * LogK) |
Hard |
TODO: merge-sort, bottom-up |
|
| Problem |
Solution |
Time |
Difficulty |
Tag |
Note |
| 62.unique-paths |
python |
O(M * N) |
Medium |
Coordinates |
|
| 63.unique-paths-ii |
python |
O(M * N) |
Medium |
Coordinates |
|
| 64.minimum-path-sum |
python |
O(M * N) |
Medium |
Coordinates |
|
| 70.climbing-stairs |
python |
O(N) |
Easy |
Coordinates |
|
| 120.triangle |
python |
O(N^2) |
Medium |
Coordinates |
|
| 300.longest-increasing-subsequence |
cpp, python |
O(N^2) |
Medium |
|
follow-up is tricky |
| 354.russian-doll-envelopes |
cpp, python |
O(N^2) |
Hard |
TODO: Python Version Time Limit Exceeded |
|
| 368.largest-divisible-subset |
cpp |
O(N^2) |
Medium |
|
|
| 403.frog-jump |
cpp |
O(N^2) |
Hard |
|
|
| Problem |
Solution |
Time |
Difficulty |
Tag |
Note |
| 45.jump-game-ii |
python |
O(N) |
Hard |
|
|
| 55.jump-game |
python |
O(N) |
Medium |
dynamic-programming |
|
| Problem |
Solution |
Time |
Difficulty |
Tag |
Note |
| 128.longest-consecutive-sequence |
cpp |
O(N) |
Hard |
|
|
| 261.graph-valid-tree |
python |
O(E) |
Medium |
BFS/DFS |
E = len(edges) |
| 305.number-of-islands-ii |
python |
O(N) |
Hard |
|
N = len(positions) |