- RIP to my old Leetcode repository, where there were ever
5700+
stars and2200+
forks. πΌ - Since free questions may be even accidentally taken down by some companies, only solutions will be post on now.
- For more solutions of questions, you can see my LintCode repository.
- There are new LeetCode questions every week. I'll keep updating for full summary and better solutions.
- Thanks for starring this repository and sending thanks notes to cheer me up. I'll make this repository better and better.
- Notes: "π" means you need to subscribe to LeetCode premium membership for the access to premium questions.
- Bit Manipulation
- Array
- String
- Linked List
- Stack
- Queue
- Heap
- Tree
- Hash Table
- Math
- Two Pointers
- Sort
- Recursion
- Binary Search
- Binary Search Tree
- Breadth-First Search
- Depth-First Search
- Backtracking
- Dynamic Programming
- Greedy
- Graph
- Geometry
- Simulation
- Design
- C++
- Python
# | Title | Solution | Time | Space | Difficulty | Tag | Note |
---|---|---|---|---|---|---|---|
020 | Valid Parentheses | C++ Python | O(n) | O(n) | Easy | ||
032 | Longest Valid Parentheses | C++ Python | O(n) | O(1) | Hard | ||
071 | Simplify Path | C++ Python | O(n) | O(n) | Medium | ||
084 | Largest Rectangle in Histogram | C++ Python | O(n) | O(n) | Hard | Ascending Stack, DP | |
085 | Maximal Rectangle | C++ Python | O(m * n) | O(n) | Hard | EPI | Ascending Stack |
101 | Symmetric Tree | C++ Python | O(n) | O(h) | Easy | ||
150 | Evaluate Reverse Polish Notation | C++ Python | O(n) | O(n) | Medium | ||
155 | Min Stack | C++ Python | O(n) | O(1) | Easy | ||
173 | Binary Search Tree Iterator | C++ Python | O(1) | O(h) | Medium | ||
224 | Basic Calculator | C++ Python | O(n) | O(n) | Hard | ||
227 | Basic Calculator II | C++ Python | O(n) | O(n) | Medium | ||
232 | Implement Queue using Stacks | C++ Python | O(1), amortized | O(n) | Easy | EPI, LintCode | |
255 | Verify Preorder Sequence in Binary Search Tree | C++ Python | O(n) | O(1) | Medium | π | |
272 | Closest Binary Search Tree Value II | C++ Python | O(h + k) | O(h) | Hard | π | |
331 | Verify Preorder Serialization of a Binary Tree | C++ Python | O(n) | O(1) | Medium | ||
341 | Flatten Nested List Iterator | C++ Python | O(n) | O(h) | Medium | π | Iterator |
385 | Mini Parser | C++ Python | O(n) | O(h) | Medium | ||
394 | Decode String | C++ Python | O(n) | O(h) | Medium | ||
439 | Ternary Expression Parser | C++ Python | O(n) | O(1) | Medium | π | |
456 | 132 Pattern | C++ Python | O(n) | O(n) | Medium | ||
636 | Exclusive Time of Functions | C++ Python | O(n) | O(n) | Medium | ||
682 | Baseball Game | C++ Python | O(n) | O(n) | Easy | ||
726 | Number of Atoms | C++ Python | O(n) | O(n) | Hard | ||
735 | Asteroid Collision | C++ Python | O(n) | O(n) | Medium | ||
736 | Parse Lisp Expression | C++ Python | O(n^2) | O(n^2) | Hard | ||
739 | Daily Temperatures | C++ Python | O(n) | O(n) | Medium | ||
770 | Basic Calculator IV | C++ Python | add: O(d * t) sub: O(d * t) mul: O(d * t^2) eval: O(d * t) to_list: O(d * tlogt) |
O(e + d * t) | Hard | ||
772 | Basic Calculator III | C++ Python | O(n) | O(n) | Hard | ||
853 | Car Fleet | C++ Python | O(nlogn) | O(n) | Medium | ||
856 | Score of Parentheses | C++ Python | O(n) | O(1) | Medium | ||
872 | Leaf-Similar Trees | C++ Python | O(n) | O(h) | Easy | ||
895 | Maximum Frequency Stack | C++ Python | O(1) | O(n) | Hard | Hash | |
901 | Online Stock Span | C++ Python | O(n) | O(n) | Medium |
# | Title | Solution | Time | Space | Difficulty | Tag | Note |
---|---|---|---|---|---|---|---|
239 | Sliding Window Maximum | C++ Python | O(n) | O(k) | Hard | EPI, LintCode | |
281 | Zigzag Iterator | C++ Python | O(n) | O(k) | Medium | π | |
346 | Moving Average from Data Stream | C++ Python | O(1) | O(w) | Easy | π | |
862 | Shortest Subarray with Sum at Least K | C++ Python | O(n) | O(n) | Hard | ||
933 | Number of Recent Calls | C++ Python | O(1) on average | O(w) | Easy |
# | Title | Solution | Time | Space | Difficulty | Tag | Note |
---|---|---|---|---|---|---|---|
264 | Ugly Number II | C++ Python | O(n) | O(1) | Medium | CTCI, LintCode | BST, Heap |
295 | Find Median from Data Stream | C++ Python | O(nlogn) | O(n) | Hard | EPI, LintCode | BST, Heap |
313 | Super Ugly Number | C++ Python | O(n * k) | O(n + k) | Medium | BST, Heap | |
358 | Rearrange String k Distance Apart | C++ Python | O(n) | O(n) | Hard | π | Greedy, Heap |
373 | Find K Pairs with Smallest Sums | C++ Python | O(k * log(min(n, m, k))) | O(min(n, m, k)) | Medium | ||
378 | Kth Smallest Element in a Sorted Matrix | C++ Python | O(k * log(min(n, m, k))) | O(min(n, m, k)) | Medium | LintCode | |
407 | Trapping Rain Water II | C++ Python | O(m * n * (logm + logn)) | O(m * n) | Hard | LintCode | |
632 | Smallest Range | C++ Python | O(nlogk) | O(k) | Hard | ||
846 | Hand of Straights | C++ Python | O(nlogn) | O(n) | Medium | ||
855 | Exam Room | C++ Python | seat: O(logn) leave: O(logn) |
O(n) | Medium | BST, Hash | |
857 | Minimum Cost to Hire K Workers | C++ Python | O(nlogn) | O(n) | Hard | Sort | |
871 | Minimum Number of Refueling Stops | C++ Python | O(nlogn) | O(n) | Hard | Sort |
# | Title | Solution | Time | Space | Difficulty | Tag | Note |
---|---|---|---|---|---|---|---|
094 | Binary Tree Inorder Traversal | C++ Python | O(n) | O(1) | Medium | Morris Traversal |
|
099 | Recover Binary Search Tree | C++ Python | O(n) | O(1) | Hard | Morris Traversal |
|
144 | Binary Tree Preorder Traversal | C++ Python | O(n) | O(1) | Medium | Morris Traversal |
|
145 | Binary Tree Postorder Traversal | C++ Python | O(n) | O(1) | Hard | Morris Traversal |
|
208 | Implement Trie (Prefix Tree) | C++ Python | O(n) | O(1) | Medium | Trie | |
211 | Add and Search Word - Data structure design | C++ Python | O(min(n, h)) | O(min(n, h)) | Medium | Trie, DFS | |
226 | Invert Binary Tree | C++ Python | O(n) | O(h), O(w) | Easy | ||
297 | Serialize and Deserialize Binary Tree | C++ Python | O(n) | O(h) | Hard | LintCode | DFS |
307 | Range Sum Query - Mutable | C++ Python | ctor: O(n), update: O(logn), query: O(logn) | O(n) | Medium | LintCode | DFS, Segment Tree, BIT |
308 | Range Sum Query 2D - Mutable | C++ Python | ctor: O(m * n), update: O(logm + logn), query: O(logm + logn) | O(m * n) | Hard | π | DFS, Segment Tree, BIT |
315 | Count of Smaller Numbers After Self | C++ Python | O(nlogn) | O(n) | Hard | LintCode | BST, BIT, Divide and Conquer |
525 | Contiguous Array | C++ Python | O(n) | O(n) | Medium | ||
529 | Minesweeper | C++ Python | O(m * n) | O(m + n) | Medium | ||
536 | Construct Binary Tree from String | C++ Python | O(n) | O(h) | Medium | π | |
538 | Convert BST to Greater Tree | C++ Python | O(n) | O(h) | Easy | ||
543 | Diameter of Binary Tree | C++ Python | O(n) | O(h) | Easy | ||
545 | Boundary of Binary Tree | C++ Python | O(n) | O(h) | Medium | π | |
548 | Split Array with Equal Sum | C++ Python | O(n^2) | O(n) | Medium | π | |
563 | Binary Tree Tilt | C++ Python | O(n) | O(n) | Easy | ||
572 | Subtree of Another Tree | C++ Python | O(m * n) | O(h) | Easy | ||
606 | Construct String from Binary Tree | C++ Python | O(n) | O(h) | Easy | ||
617 | Merge Two Binary Trees | C++ Python | O(n) | O(h) | Easy | ||
623 | Add One Row to Tree | C++ Python | O(n) | O(h) | Medium | ||
637 | Average of Levels in Binary Tree | C++ Python | O(n) | O(h) | Easy | ||
652 | Find Duplicate Subtrees | C++ Python | O(n) | O(n) | Medium | DFS, Hash | |
653 | Two Sum IV - Input is a BST | C++ Python | O(n) | O(h) | Easy | Two Pointers | |
654 | Maximum Binary Tree | C++ Python | O(n) | O(n) | Medium | LintCode | Descending Stack |
655 | Print Binary Tree | C++ Python | O(n) | O(h) | Medium | ||
662 | Maximum Width of Binary Tree | C++ Python | O(n) | O(h) | Medium | DFS | |
663 | Equal Tree Partition | C++ Python | O(n) | O(n) | Medium | π | Hash |
677 | Map Sum Pairs | C++ Python | O(n) | O(t) | Medium | Trie | |
684 | Redundant Connection | C++ Python | O(n) | O(n) | Medium | Union Find | |
685 | Redundant Connection II | C++ Python | O(n) | O(n) | Hard | Union Find | |
687 | Longest Univalue Path | C++ Python | O(n) | O(h) | Easy | ||
699 | Falling Squares | C++ Python | O(nlogn) | O(n) | Hard | Segment Tree | |
814 | Binary Tree Pruning | C++ Python | O(n) | O(h) | Medium | DFS | |
850 | Rectangle Area II | C++ Python | O(nlogn) | O(n) | Hard | Segment Tree | |
863 | All Nodes Distance K in Binary Tree | C++ Python | O(n) | O(n) | Medium | DFS + BFS | |
866 | Smallest Subtree with all the Deepest Nodes | C++ Python | O(n) | O(h) | Medium | DFS | |
889 | Construct Binary Tree from Preorder and Postorder Traversal | C++ Python | O(n) | O(h) | Medium | DFS, stack | |
897 | Increasing Order Search Tree | C++ Python | O(n) | O(h) | Easy | DFS | |
919 | Complete Binary Tree Inserter | C++ Python | ctor: O(n) insert: O(1) get_root: O(1) |
O(n) | Medium |
# | Title | Solution | Time | Space | Difficulty | Tag | Note |
---|---|---|---|---|---|---|---|
056 | Merge Intervals | C++ Python | O(nlogn) | O(1) | Hard | ||
057 | Insert Interval | C++ Python | O(n) | O(1) | Hard | ||
075 | Sort Colors | C++ Python | O(n) | O(1) | Medium | Tri Partition | |
088 | Merge Sorted Array | C++ Python | O(n) | O(1) | Easy | ||
147 | Insertion Sort List | C++ Python | O(n^2) | O(1) | Medium | ||
148 | Sort List | C++ Python | O(nlogn) | O(logn) | Medium | ||
164 | Maximum Gap | C++ Python | O(n) | O(n) | Hard | Tricky | |
179 | Largest Number | C++ Python | O(nlogn) | O(1) | Medium | ||
218 | The Skyline Problem | C++ Python | O(nlogn) | O(n) | Hard | Sort, BST | |
252 | Meeting Rooms | C++ Python | O(nlogn) | O(n) | Easy | π | |
253 | Meeting Rooms II | C++ Python | O(nlogn) | O(n) | Medium | π | |
274 | H-Index | C++ Python | O(n) | O(n) | Medium | Counting Sort | |
280 | Wiggle Sort | C++ Python | O(n) | O(1) | Medium | π | |
324 | Wiggle Sort II | C++ Python | O(n) on average | O(1) | Medium | variant of Sort Colors | Tri Partition |
347 | Top K Frequent Elements | C++ Python | O(n) | O(n) | Medium | Quick Select, Heap, Bucket Sort | |
406 | Queue Reconstruction by Height | C++ Python | O(n * sqrt(n)) | O(n) | Medium | Tricky | |
451 | Sort Characters By Frequency | C++ Python | O(n) | O(n) | Medium | ||
692 | Top K Frequent Words | C++ Python | O(n + klogk) on average | O(n) | Medium | Quick Select, Heap, Bucket Sort |
# | Title | Solution | Time | Space | Difficulty | Tag | Note |
---|---|---|---|---|---|---|---|
220 | Contains Duplicate III | C++ Python | O(nlogk) | O(k) | Medium | ||
230 | Kth Smallest Element in a BST | C++ Python | O(max(h, k)) | O(min(h, k)) | Medium | ||
235 | Lowest Common Ancestor of a Binary Search Tree | C++ Python | O(h) | O(1) | Easy | EPI | |
270 | Closest Binary Search Tree Value | C++ Python | O(h) | O(1) | Easy | π | |
285 | Inorder Successor in BST | C++ Python | O(h) | O(1) | Medium | π | |
352 | Data Stream as Disjoint Intervals | C++ Python | O(logn) | O(n) | Hard | ||
449 | Serialize and Deserialize BST | C++ Python | O(n) | O(h) | Medium | ||
450 | Delete Node in a BST | C++ Python | O(h) | O(h) | Medium | ||
530 | Minimum Absolute Difference in BST | C++ Python | O(n) | O(h) | Easy | ||
776 | Split BST | C++ Python | O(n) | O(h) | Medium | π | |
783 | Minimum Distance Between BST Nodes | C++ Python | O(n) | O(h) | Easy |
# | Title | Solution | Time | Space | Difficulty | Tag | Note |
---|---|---|---|---|---|---|---|
102 | Binary Tree Level Order Traversal | C++ Python | O(n) | O(n) | Easy | ||
107 | Binary Tree Level Order Traversal II | Python | O(n) | O(n) | Easy | ||
103 | Binary Tree Zigzag Level Order Traversal | Python | O(n) | O(n) | Medium | ||
117 | Populating Next Right Pointers in Each Node II | Python | O(n) | O(1) | Hard | ||
127 | Word Ladder | Python | O(n * d) | O(d) | Medium | ||
130 | Surrounded Regions | C++ Python | O(m * n) | O(m + n) | Medium | ||
133 | Clone Graph | Python | O(n) | O(n) | Medium | ||
207 | Course Schedule | Python | O(|V| + |E|) | O(|E|) | Medium | Topological Sort | |
210 | Course Schedule II | Python | O(|V| + |E|) | O(|E|) | Medium | Topological Sort | |
261 | Graph Valid Tree | C++ Python | O(|V| + |E|) | O(|V| + |E|) | Medium | π | |
269 | Alien Dictionary | C++ Python | O(n) | O(1) | Hard | π | Topological Sort, BFS, DFS |
286 | Walls and Gates | C++ Python | O(m * n) | O(g) | Medium | π | |
310 | Minimum Height Trees | C++ Python | O(n) | O(n) | Medium | ||
317 | Shortest Distance from All Buildings | C++ Python | O(k * m * n) | O(m * n) | Hard | π | |
433 | Minimum Genetic Mutation | C++ Python | O(n * b) | O(b) | Medium | ||
444 | Sequence Reconstruction | C++ Python | O(n * s) | O(n) | Medium | π | Topological Sort |
542 | 01 Matrix | C++ Python | O(m * n) | O(m * n) | Medium | DP | |
666 | Path Sum IV | C++ Python | O(n) | O(w) | Medium | π | Topological Sort |
675 | Cut Off Trees for Golf Event | C++ Python | O(t * m * n) | O(m * n) | Hard | A* Search Algorithm |
|
742 | Closest Leaf in a Binary Tree | C++ Python | O(n) | O(n) | Medium | ||
743 | Network Delay Time | C++ Python | O(|E| * log|V|) | O(|E|) | Medium | Dijkstra's algorithm |
|
752 | Open the Lock | C++ Python | O(k * n^k + d) | O(k * n^k + d) | Medium | ||
773 | Sliding Puzzle | C++ Python | O((m * n) * (m * n)!) | O((m * n) * (m * n)!) | Hard | A* Search Algorithm |
|
787 | Cheapest Flights Within K Stops | C++ Python | O(|E| * log|V|) | O(|E|) | Medium | Dijkstra's algorithm |
|
815 | Bus Routes | C++ Python | O(|E| + |V|) | O(|E| + |V|) | Hard | ||
854 | K-Similar Strings | C++ Python | O(n * n!/(c_a!*...*c_z!)) | O(n * n!/(c_a!*...*c_z!)) | Hard | ||
865 | Shortest Path to Get All Keys | C++ Python | O(k * r * c + k^3*2^k) | O(k*2^k) | Hard | Dijkstra's algorithm |
|
882 | Reachable Nodes In Subdivided Graph | C++ Python | O(|E| * log|V|) | O(|E|) | Hard | Dijkstra's algorithm |
|
886 | Possible Bipartition | C++ Python | O(|V| + |E|) | O(|V| + |E|) | Medium | ||
934 | Shortest Bridge | C++ Python | O(n^2) | O(n^2) | Medium | BFS, DFS |
# | Title | Solution | Time | Space | Difficulty | Tag | Note |
---|---|---|---|---|---|---|---|
112 | Path Sum | Python | O(n) | O(h) | Easy | ||
113 | Path Sum II | Python | O(n) | O(h) | Medium | ||
199 | Binary Tree Right Side View | Python | O(n) | O(h) | Medium | ||
200 | Number of Islands | Python | O(m * n) | O(m * n) | Medium | ||
236 | Lowest Common Ancestor of a Binary Tree | C++ Python | O(n) | O(h) | Medium | EPI | |
247 | Strobogrammatic Number II | C++ Python | O(n^2 * 5^(n/2)) | O(n) | Medium | π | |
250 | Count Univalue Subtrees | C++ Python | O(n) | O(h) | Medium | π | |
257 | Binary Tree Paths | C++ Python | O(n * h) | O(h) | Easy | ||
282 | Expression Add Operators | C++ Python | O(4^n) | O(n) | Hard | ||
301 | Remove Invalid Parentheses | C++ Python | O(C(n, c)) | O(c) | Hard | ||
329 | Longest Increasing Path in a Matrix | C++ Python | O(m * n) | O(m * n) | Hard | ||
332 | Reconstruct Itinerary | C++ Python | O(t! / (n1! * n2! * ... nk!)) | O(t) | Medium | ||
339 | Nested List Weight Sum | C++ Python | O(n) | O(h) | Easy | π | |
364 | Nested List Weight Sum II | C++ Python | O(n) | O(h) | Medium | π | |
366 | Find Leaves of Binary Tree | C++ Python | O(n) | O(h) | Medium | π | |
399 | Evaluate Division | C++ Python | O(q * |V|!) | O(e) | Medium | ||
417 | Pacific Atlantic Water Flow | C++ Python | O(m * n) | O(m * n) | Medium | ||
440 | K-th Smallest in Lexicographical Order | C++ Python | O(logn) | O(logn) | Hard | ||
464 | Can I Win | C++ Python | O(n!) | O(n) | Medium | ||
515 | Find Largest Value in Each Tree Row | C++ Python | O(n) | O(h) | Medium | ||
547 | Friend Circles | C++ Python | O(n^2) | O(n) | Medium | Union Find | |
582 | Kill Process | C++ Python | O(n) | O(n) | Medium | π | DFS, BFS |
638 | Shopping Offers | C++ Python | O(n * 2^n) | O(n) | Medium | ||
690 | Employee Importance | C++ Python | O(n) | O(h) | Easy | DFS, BFS | |
694 | Number of Distinct Islands | C++ Python | O(m * n) | O(m * n) | Medium | π | |
695 | Max Area of Island | C++ Python | O(m * n) | O(m * n) | Easy | ||
711 | Number of Distinct Islands II | C++ Python | O((m * n) * log(m * n)) | O(m * n) | Hard | π | Hash |
733 | Max Area of Island | C++ Python | O(m * n) | O(m * n) | Easy | ||
749 | Contain Virus | C++ Python | O((m * n)^(4/3)) | O(m * n) | Hard | Simulation | |
753 | Cracking the Safe | C++ Python | O(k^n) | O(k^n) | Hard | de Bruijn sequences , Lyndon word |
|
756 | Pyramid Transition Matrix | C++ Python | O(a^b) | O(a^b) | Medium | ||
785 | Is Graph Bipartite? | C++ Python | O(|V| + |E|) | O(|V|) | Medium | ||
797 | All Paths From Source to Target | C++ Python | O(p + r * n) | O(n) | Medium | ||
802 | Find Eventual Safe States | C++ Python | O(|V| + |E|) | O(|V|) | Medium | ||
827 | Making A Large Island | C++ Python | O(n^2) | O(n^2) | Hard | ||
834 | Sum of Distances in Tree | C++ Python | O(n) | O(n) | Hard | ||
841 | Keys and Rooms | C++ Python | O(n!) | O(n) | Medium | ||
851 | Loud and Rich | C++ Python | O(q + r) | O(q + r) | Medium | ||
913 | Cat and Mouse | C++ Python | O(n^3) | O(n^2) | Hard |
# | Title | Solution | Time | Space | Difficulty | Tag | Note |
---|---|---|---|---|---|---|---|
017 | Letter Combinations of a Phone Number | Python | O(n * 4^n) | O(n) | Medium | ||
022 | Generate Parentheses | Python | O(4^n / n^(3/2)) | O(n) | Medium | ||
037 | Sudoku Solver | Python | O((9!)^9) | O(1) | Hard | ||
039 | Combination Sum | Python | O(k * n^k) | O(k) | Medium | ||
040 | Combination Sum II | Python | O(k * C(n, k)) | O(k) | Medium | ||
046 | Permutations | Python | O(n * n!) | O(n) | Medium | ||
047 | Permutations II | Python | O(n * n!) | O(n) | Medium | ||
051 | N-Queens | Python | O(n!) | O(n) | Hard | ||
052 | N-Queens-II | Python | O(n!) | O(n) | Hard | ||
077 | Combinations | Python | O(O(k * C(n, k))) | O(k) | Medium | ||
079 | Word Search | Python | O(m * n * l) | O(l) | Medium | ||
093 | Restore IP Addresses | Python | O(1) | O(1) | Medium | ||
078 | Subsets | C++ Python | O(n * 2^n) | O(1) | Medium | ||
090 | Subsets II | C++ Python | O(n * 2^n) | O(1) | Medium | ||
126 | Word Ladder II | Python | O(n * d) | O(d) | Hard | ||
131 | Palindrome Partitioning | Python | O(n^2) ~ O(2^n) | O(n^2) | Medium | ||
140 | Word Break II | C++ Python | O(n * l^2 + n * r) | O(n^2) | Hard | ||
212 | Word Search II | C++ Python | O(m * n * l) | O(l) | Hard | LintCode | Trie, DFS |
216 | Combination Sum III | C++ Python | O(k * C(n, k)) | O(k) | Medium | ||
254 | Factor Combinations | C++ Python | O(nlogn) | O(logn) | Medium | π | |
267 | Palindrome Permutation II | C++ Python | O(n * n!) | O(n) | Medium | π | |
291 | Word Pattern II | C++ Python | O(n * C(n - 1, c - 1)) | O(n + c) | Hard | π | |
294 | Flip Game II | C++ Python | O(n + c^2) | O(c) | Medium | π | DP, Hash |
320 | Generalized Abbreviation | C++ Python | O(n * 2^n) | O(n) | Medium | π | |
425 | Word Squares | C++ Python | O(n^2 * n!) | O(n^2) | Hard | π | |
526 | Beautiful Arrangement | C++ Python | O(n!) | O(n) | Medium | ||
676 | Implement Magic Dictionary | C++ Python | O(n) | O(d) | Medium | Trie, DFS | |
679 | 24 Game | C++ Python | O(1) | O(1) | Hard | DFS | |
698 | Partition to K Equal Sum Subsets | C++ Python | O(n * 2^n) | O(2^n) | Medium | DFS, DP, Memoization | |
718 | Maximum Length of Repeated Subarray | C++ Python | O(m * n) | O(min(m, n)) | Medium | DP, Hash, Binary Search | |
784 | Letter Case Permutation | C++ Python | O(n * 2^n) | O(1) | Easy |
# | Title | Solution | Time | Space | Difficulty | Tag | Note |
---|---|---|---|---|---|---|---|
011 | Container With Most Water | C++ Python | O(n) | O(1) | Medium | ||
042 | Trapping Rain Water | C++ Python | O(n) | O(1) | Hard | Tricky | |
044 | Wildcard Matching | Python | O(m + n) | O(1) | Hard | Tricky | |
045 | Jump Game II | Python | O(n) | O(1) | Hard | ||
055 | Jump Game | Python | O(n) | O(1) | Medium | ||
122 | Best Time to Buy and Sell Stock II | Python | O(n) | O(1) | Easy | ||
134 | Gas Station | Python | O(n) | O(1) | Medium | ||
135 | Candy | C++ Python | O(n) | O(n) | Hard | ||
316 | Remove Duplicate Letters | C++ Python | O(n) | O(k) | Hard | Ascending Stack | |
321 | Create Maximum Number | C++ Python | O(k * (m + n + k)) ~ O(k * (m + n + k^2)) | O(m + n + k^2) | Hard | variant of Delete Digits | Greedy, DP |
330 | Patching Array | C++ Python | O(s + logn) | O(1) | Hard | ||
376 | Wiggle Subsequence | C++ Python | O(n) | O(1) | Medium | ||
392 | Is Subsequence | C++ Python | O(n) | O(1) | Medium | ||
397 | Integer Replacement | C++ Python | O(n) | O(1) | Medium | Math | |
402 | Remove K Digits | C++ Python | O(n) | O(n) | Medium | LintCode | |
435 | Non-overlapping Intervals | C++ Python | O(nlogn) | O(1) | Medium | Line Sweep | |
452 | Minimum Number of Arrows to Burst Balloons | C++ Python | O(nlogn) | O(1) | Medium | ||
455 | Assign Cookies | C++ Python | O(nlogn) | O(1) | Easy | ||
621 | Task Scheduler | C++ Python | O(n) | O(1) | Medium | ||
630 | Course Schedule III | C++ Python | O(nlogn) | O(k) | Hard | ||
646 | Maximum Length of Pair Chain | C++ Python | O(nlogn) | O(1) | Medium | similar to Non-overlapping Intervals | Line Sweep |
649 | Dota2 Senate | C++ Python | O(n) | O(n) | Medium | ||
659 | Split Array into Consecutive Subsequences | C++ Python | O(n) | O(1) | Medium | ||
738 | Monotone Increasing Digits | C++ Python | O(1) | O(1) | Medium | ||
757 | Set Intersection Size At Least Two | C++ Python | O(nlogn) | O(n) | Hard | ||
759 | Employee Free Time | C++ Python | O(m * logn) | O(n) | Hard | ||
763 | Partition Labels | C++ Python | O(n) | O(n) | Medium | ||
767 | Reorganize String | C++ Python | O(n) | O(1) | Medium | ||
798 | Smallest Rotation with Highest Score | C++ Python | O(n) | O(1) | Hard | ||
843 | Guess the Word | C++ Python | O(n^2) | O(n) | Hard | MinMax | |
861 | Score After Flipping Matrix | C++ Python | O(r * c) | O(1) | Medium | ||
870 | Advantage Shuffle | C++ Python | O(nlogn) | O(n) | Medium | ||
881 | Boats to Save People | C++ Python | O(nlogn) | O(n) | Medium | ||
936 | Stamping The Sequence | C++ Python | O((n - m) * m) | O((n - m) * m) | Hard |
# | Title | Solution | Time | Space | Difficulty | Tag | Note |
---|---|---|---|---|---|---|---|
765 | Couples Holding Hands | C++ Python | O(n) | O(n) | Hard | ||
924 | Minimize Malware Spread | C++ Python | O(n^2) | O(n) | Hard | Union Find | |
928 | Minimize Malware Spread II | C++ Python | O(n^2) | O(n) | Hard | Union Find |
# | Title | Solution | Time | Space | Difficulty | Tag | Note |
---|---|---|---|---|---|---|---|
587 | Erect the Fence | C++ Python | O(nlogn) | O(n) | Hard | Monotone Chain |
|
892 | Surface Area of 3D Shapes | C++ Python | O(n^2) | O(1) | Easy |
# | Title | Solution | Time | Space | Difficulty | Tag | Note |
---|---|---|---|---|---|---|---|
874 | Walking Robot Simulation | C++ Python | O(n + k) | O(k) | Easy |
# | Title | Solution | Time | Space | Difficulty | Tag | Note |
---|---|---|---|---|---|---|---|
146 | LRU Cache | C++ Python | O(1) | O(k) | Hard | ||
225 | Implement Stack using Queues | C++ Python | push: O(n), pop: O(1), top: O(1) | O(n) | Easy | ||
284 | Peeking Iterator | C++ Python | O(1) | O(1) | Medium | ||
348 | Design Tic-Tac-Toe | C++ Python | O(1) | O(n^2) | Medium | π | |
353 | Design Snake Game | C++ Python | O(1) | O(s) | Medium | π | Deque |
355 | Design Twitter | C++ Python | O(klogu) | O(t + f) | Medium | LintCode | Heap |
359 | Logger Rate Limiter | C++ Python | O(1), amortized | O(k) | Easy | π | Deque |
362 | Design Hit Counter | C++ Python | O(1), amortized | O(k) | Medium | π | Deque |
379 | Design Phone Directory | C++ Python | O(1) | O(n) | Medium | π | |
380 | Insert Delete GetRandom O(1) | C++ Python | O(1) | O(n) | Hard | ||
381 | Insert Delete GetRandom O(1) - Duplicates allowed | C++ Python | O(1) | O(n) | Hard | ||
432 | All O`one Data Structure | C++ Python | O(1) | O(n) | Hard | ||
460 | LFU Cache | C++ Python | O(1) | O(k) | Hard | ||
535 | Encode and Decode TinyURL | C++ Python | O(1) | O(n) | Medium | ||
588 | Design In-Memory File System | C++ Python | ls: O(l + klogk) mkdir: O(l) addContentToFile: O(l + c) readContentFromFile: O(l + c) |
O(n + s) | Hard | π | |
604 | Design Compressed String Iterator | C++ Python | O(1) | O(1) | Easy | π | |
631 | Design Excel Sum Formula | C++ Python | set: O((r * c)^2) get: O(1) sum: O((r * c)^2) |
O(r * c) | Hard | π | |
635 | Design Log Storage System | C++ Python | put: O(1) retrieve: O(n + dlogd) |
O(n) | Medium | π | |
642 | Design Search Autocomplete System | C++ Python | O(p^2) | O(p * t + s) | Hard | π | |
715 | Range Module | C++ Python | add: O(n) remove: O(n) query: O(logn) |
O(n) | Hard | ||
716 | Max Stack | C++ Python | push: O(logn) pop: O(logn) popMax: O(logn) top: O(1) peekMax: O(1) |
O(n) | Easy | ||
745 | Prefix and Suffix Search | C++ Python | ctor: O(w * l^2) search : O(p + s) |
O(t) | Hard | Trie | |
900 | RLE Iterator | C++ Python | O(n) | O(1) | Medium |
# | Title | Solution | Time | Space | Difficulty | Tag | Note |
---|---|---|---|---|---|---|---|
175 | Combine Two Tables | MySQL | O(m + n) | O(m + n) | Easy | ||
176 | Second Highest Salary | MySQL | O(n) | O(1) | Easy | ||
177 | Nth Highest Salary | MySQL | O(n^2) | O(n) | Medium | ||
178 | Rank Scores | MySQL | O(n^2) | O(n) | Medium | ||
180 | Consecutive Numbers | MySQL | O(n) | O(n) | Medium | ||
181 | Employees Earning More Than Their Managers | MySQL | O(n^2) | O(1) | Easy | ||
182 | Duplicate Emails | MySQL | O(n^2) | O(n) | Easy | ||
183 | Customers Who Never Order | MySQL | O(n^2) | O(1) | Easy | ||
184 | Department Highest Salary | MySQL | O(n^2) | O(n) | Medium | ||
185 | Department Top Three Salaries | MySQL | O(n^2) | O(n) | Hard | ||
196 | Delete Duplicate Emails | MySQL | O(n^2) | O(n) | Easy | ||
197 | Rising Temperature | MySQL | O(n^2) | O(n) | Easy | ||
262 | Trips and Users | MySQL | O((t * u) + tlogt) | O(t) | Hard |
# | Title | Solution | Time | Space | Difficulty | Tag | Note |
---|---|---|---|---|---|---|---|
192 | Word Frequency | Shell | O(n) | O(k) | Medium | ||
193 | Valid Phone Numbers | Shell | O(n) | O(1) | Easy | ||
194 | Transpose File | Shell | O(n^2) | O(n^2) | Medium | ||
195 | Tenth Line | Shell | O(n) | O(1) | Easy |