Skip to content

jarrekk/LeetCode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

There are 447 Algorithms / 13 Database / 4 Shell / 4 Draft questions on LeetCode Online Judge until 2016-12-18. The number of questions is increasing recently. Here is the classification of all 468 questions. For more questions and solutions, you can see my LintCode repository. I'll keep updating for full summary and better solutions. Stay tuned for updates. (Notes: "πŸ“–" means you need to subscribe to LeetCode premium membership for the access to premium questions.)

Algorithms

Database

Shell

Bit Manipulation

# Title Solution Time Space Difficulty Tag Note
136 Single Number Python O(n) O(1) Easy
137 Single Number II Python O(n) O(1) Medium
190 Reverse Bits Python O(1) O(1) Easy
191 Number of 1 Bits Python O(1) O(1) Easy
201 Bitwise AND of Numbers Range Python O(1) O(1) Medium
231 Power of Two Python O(1) O(1) Easy LintCode
260 Single Number III Python O(n) O(1) Medium
268 Missing Number Python O(n) O(1) Medium LintCode
318 Maximum Product of Word Lengths Python O(n) ~ O(n^2) O(n) Medium Bit Manipulation, Counting Sort, Pruning
342 Power of Four Python O(1) O(1) Easy
371 Sum of Two Integers Python O(1) O(1) Easy LintCode
389 Find the Difference Python O(n) O(1) Easy
393 UTF-8 Validation Python O(n) O(1) Medium
401 Binary Watch Python O(1) O(1) Easy
411 Minimum Unique Word Abbreviation Python O(2^n) O(n) Hard πŸ“–
421 Maximum XOR of Two Numbers in an Array Python O(n) O(1) Medium
461 Hamming Distance Python O(1) O(1) Easy
462 Minimum Moves to Equal Array Elements II Python O(n) on average O(1) Medium
477 Total Hamming Distance Python O(n) O(1) Medium

Array

# Title Solution Time Space Difficulty Tag Note
15 3 Sum Python O(n^2) O(1) Medium Two Pointers
16 3 Sum Closest Python O(n^2) O(1) Medium Two Pointers
18 4 Sum Python O(n^3) O(1) Medium Two Pointers
26 Remove Duplicates from Sorted Array Python O(n) O(1) Easy Two Pointers
27 Remove Element Python O(n) O(1) Easy
31 Next Permutation Python O(n) O(1) Medium Tricky
41 First Missing Positive Python O(n) O(1) Hard Tricky
48 Rotate Image Python O(n^2) O(1) Medium
54 Spiral Matrix Python O(m * n) O(1) Medium
59 Spiral Matrix II Python O(n^2) O(1) Medium
66 Plus One Python O(n) O(1) Easy
73 Set Matrix Zeroes Python O(m * n) O(1) Medium
80 Remove Duplicates from Sorted Array II Python O(n) O(1) Medium Two Pointers
118 Pascal's Triangle Python O(n^2) O(1) Easy
119 Pascal's Triangle II Python O(n^2) O(1) Easy
121 Best Time to Buy and Sell Stock Python O(n) O(1) Easy
128 Longest Consecutive Sequence Python O(n) O(n) Hard Tricky
157 Read N Characters Given Read4 Python O(n) O(1) Easy πŸ“–
158 Read N Characters Given Read4 II - Call multiple times Python O(n) O(1) Hard πŸ“–
163 Missing Ranges Python O(n) O(1) Medium πŸ“–
169 Majority Element Python O(n) O(1) Easy
189 Rotate Array Python O(n) O(1) Easy
209 Minimum Size Subarray Sum Python O(n) O(1) Medium Binary Search
215 Kth Largest Element in an Array Python O(n) ~ O(n^2) O(1) Medium EPI
228 Summary Ranges Python O(n) O(1) Medium
229 Majority Element II Python O(n) O(1) Medium
238 Product of Array Except Self Python O(n) O(1) Medium LintCode
240 Search a 2D Matrix II Python O(m + n) O(1) Medium EPI, LintCode
243 Shortest Word Distance Python O(n) O(1) Easy πŸ“–
245 Shortest Word Distance III Python O(n) O(1) Medium πŸ“–
251 Flatten 2D Vector Python O(1) O(1) Medium πŸ“–
277 Find the Celebrity Python O(n) O(1) Medium πŸ“–, EPI
289 Game of Life Python O(m * n) O(1) Medium
293 Flip Game Python O(n * (c+1)) O(1) Easy πŸ“–
296 Best Meeting Point Python O(m * n) O(m + n) Hard πŸ“–
311 Sparse Matrix Multiplication Python O(m * n * l) O(m * l) Medium πŸ“–
334 Increasing Triplet Subsequence Python O(n) O(1) Medium
370 Range Addition Python O(k + n) O(1) Medium πŸ“–
384 Shuffle an Array Python O(n) O(n) Medium EPI
396 Rotate Function Python O(n) O(1) Easy
412 Fizz Buzz Python O(n) O(1) Easy
414 Third Maximum Number Python O(n) O(1) Easy
419 Battleships in a Board Python O(m * n) O(1) Medium
422 Valid Word Square Python O(m * n) O(1) Easy πŸ“–
442 Find All Duplicates in an Array Python O(n) O(1) Medium
448 Find All Numbers Disappeared in an Array Python O(n) O(1) Easy

String

# Title Solution Time Space Difficulty Tag Note
5 Longest Palindromic Substring Python O(n) O(n) Medium Manacher's Algorithm
6 ZigZag Conversion Python O(n) O(1) Easy
8 String to Integer (atoi) Python O(n) O(1) Easy
14 Longest Common Prefix Python O(n * k) O(1) Easy
28 Implement strStr() Python O(n + k) O(k) Easy KMP Algorithm
38 Python O(n * 2^n) O(2^n) Easy
43 Multiply Strings Python O(m * n) O(m + n) Medium
58 Length of Last Word Python O(n) O(1) Easy
67 Add Binary Python O(n) O(1) Easy
68 Text Justification Python O(n) O(1) Hard
125 Valid Palindrome Python O(n) O(1) Easy
151 Reverse Words in a String Python O(n) O(1) Medium
161 One Edit Distance Python O(m + n) O(1) Medium πŸ“–
165 Python O(n) O(1) Easy
186 Reverse Words in a String II Python O(n) O(1) Medium πŸ“–
214 Shortest Palindrome Python O(n) O(n) Hard KMP Algorithm Manacher's Algorithm
242 Valid Anagram Python O(n) O(1) Easy LintCode
271 Encode and Decode Strings Python O(n) O(1) Medium πŸ“–
273 Integer to English Words Python O(logn) O(1) Hard
306 Addictive Number Python O(n^3) O(n) Medium
383 Ransom Note Python O(n) O(1) Easy EPI
405 Python O(n) O(1) Easy
408 Valid Word Abbreviation Python O(n) O(1) Easy πŸ“–
415 Add Strings Python O(n) O(1) Easy
420 Strong Password Checker Python O(n) O(1) Hard
434 Number of Segments in a String Python O(n) O(1) Easy
459 Repeated Substring Pattern Python O(n) O(n) Easy KMP Algorithm
468 Validate IP Address Python O(1) O(1) Medium
556 Next Greater Element III Python O(1) O(1) Medium
557 Reverse Words in a String III Python O(n) O(1) Easy

Linked List

# Title Solution Time Space Difficulty Tag Note
2 Add Two Numbers Python O(n) O(1) Medium
21 Merge Two Sorted Lists Python O(n) O(1) Easy
23 Merge k Sorted Lists Python O(nlogk) O(1) Hard Heap, Divide and Conquer
24 Swap Nodes in Pairs Python O(n) O(1) Easy
25 Reverse Nodes in k-Group Python O(n) O(1) Hard
61 Rotate List Python O(n) O(1) Medium
82 Remove Duplicates from Sorted List II Python O(n) O(1) Medium
83 Remove Duplicates from Sorted List Python O(n) O(1) Easy
92 Reverse Linked List II Python O(n) O(1) Medium
138 Python O(n) O(1) Hard
160 Intersection of Two Linked Lists Python O(m + n) O(1) Easy
203 Remove Linked List Elements Python O(n) O(1) Easy
206 Reverse Linked List Python O(n) O(1) Easy
234 Palindrome Linked List Python O(n) O(1) Easy
237 Delete Node in a Linked List Python O(1) O(1) Easy LintCode
328 Odd Even Linked List Python O(n) O(1) Medium
369 Plus One Linked List Python O(n) O(1) Medium πŸ“– Two Pointers
445 Add Two Numbers II Python O(m + n) O(m + n) Medium

Stack

# Title Solution Time Space Difficulty Tag Note
20 Valid Parentheses Python O(n) O(n) Easy
32 Longest Valid Parentheses Python O(n) O(1) Hard
71 Simplify Path Python O(n) O(n) Medium
84 Largest Rectangle in Histogram Python O(n) O(n) Hard Ascending Stack, DP
85 Maximal Rectangle Python O(m * n) O(n) Hard EPI Ascending Stack
101 Symmetric Tree Python O(n) O(h) Easy
150 Evaluate Reverse Polish Notation Python O(n) O(n) Medium
155 Min Stack Python O(n) O(1) Easy
173 Binary Search Tree Iterator Python O(1) O(h) Medium
224 Basic Calculator Python O(n) O(n) Hard
227 Basic Calculator II Python O(n) O(n) Medium
232 Implement Queue using Stacks Python O(1), amortized O(n) Easy EPI, LintCode
255 Verify Preorder Sequence in Binary Search Tree Python O(n) O(1) Medium πŸ“–
272 Python O(h + k) O(h) Hard πŸ“–
331 Verify Preorder Serialization of a Binary Tree Python O(n) O(1) Medium
341 Flatten Nested List Iterator Python O(n) O(h) Medium πŸ“– Iterator
385 Mini Parser Python O(n) O(h) Medium
394 Decode String Python O(n) O(h) Medium
439 Ternary Expression Parser Python O(n) O(1) Medium πŸ“–
456 132 Pattern Python O(n) O(n) Medium

Queue

# Title Solution Time Space Difficulty Tag Note
239 Sliding Window Maximum Python O(n) O(k) Hard EPI, LintCode
281 Zigzag Iterator Python O(n) O(k) Medium πŸ“–
346 Moving Average from Data Stream Python O(1) O(w) Easy πŸ“–

Heap

# Title Solution Time Space Difficulty Tag Note
264 Ugly Number II Python O(n) O(1) Medium CTCI, LintCode BST, Heap
295 Find Median from Data Stream Python O(nlogn) O(n) Hard EPI, LintCode BST, Heap
313 Super Ugly Number Python O(n * k) O(n + k) Medium BST, Heap
358 Rearrange String k Distance Apart Python O(n) O(n) Hard πŸ“– Greedy, Heap
373 Find K Pairs with Smallest Sums Python O(k * log(min(n, m, k))) O(min(n, m, k)) Medium
378 Kth Smallest Element in a Sorted Matrix Python O(k * log(min(n, m, k))) O(min(n, m, k)) Medium LintCode
407 Trapping Rain Water II Python O(m * n * (logm + logn)) O(m * n) Hard LintCode

Tree

# Title Solution Time Space Difficulty Tag Note
94 Binary Tree Inorder Traversal Python O(n) O(1) Medium Morris Traversal
99 Recover Binary Search Tree Python O(n) O(1) Hard Morris Traversal
144 Binary Tree Preorder Traversal Python O(n) O(1) Medium Morris Traversal
145 Binary Tree Postorder Traversal Python O(n) O(1) Hard Morris Traversal
208 Implement Trie (Prefix Tree) Python O(n) O(1) Medium Trie
211 Add and Search Word - Data structure design Python O(min(n, h)) O(min(n, h)) Medium Trie, DFS
226 Invert Binary Tree Python O(n) O(h), O(w) Easy
297 Serialize and Deserialize Binary Tree Python O(n) O(h) Hard LintCode DFS
307 Range Sum Query - Mutable Python ctor: O(n), update: O(logn), query: O(logn) O(n) Medium LintCode DFS, Segment Tree, BIT
308 Range Sum Query 2D - Mutable Python ctor: O(m * n), update: O(logm + logn), query: O(logm + logn) O(m * n) Hard πŸ“– DFS, Segment Tree, BIT
315 Python O(nlogn) O(n) Hard LintCode BST, BIT, Divide and Conquer

Hash Table

# Title Solution Time Space Difficulty Tag Note
1 Two Sum Python O(n) O(n) Easy
3 Longest Substring Without Repeating Characters Python O(n) O(1) Medium
30 Substring with Concatenation of All Words Python O(m * n * k) O(n * k) Hard
36 Valid Sudoku Python O(9^2) O(9) Easy
49 Group Anagrams Python O(n * glogg) O(n) Medium
76 Minimum Window Substring Python O(n) O(k) Hard
149 Max Points on a Line Python O(n^2) O(n) Hard
159 Longest Substring with At Most Two Distinct Characters Python O(n) O(1) Hard πŸ“–
170 Two Sum III - Data structure design Python O(n) O(n) Easy πŸ“–
187 Repeated DNA Sequences Python O(n) O(n) Medium
202 Happy Number Python O(k) O(k) Easy
204 Python O(n) O(n) Easy
205 Isomorphic Strings Python O(n) O(1) Easy
217 Python O(n) O(n) Easy
219 Python O(n) O(n) Easy
244 Shortest Word Distance II Python ctor: O(n), lookup: O(a + b) O(n) Medium πŸ“–
246 Strobogrammatic Number Python O(n) O(1) Easy πŸ“–
249 Group Shifted Strings Python O(nlogn) O(n) Easy πŸ“–
266 Palindrome Permutation Python O(n) O(1) Easy πŸ“–
288 Unique Word Abbreviation Python ctor: O(n), lookup: O(1) O(k) Easy πŸ“–
290 Word Pattern Python O(n) O(c) Easy variant of Isomorphic Strings
299 Bulls and Cows Python O(n) O(1) Easy
305 Number of Islands II Python O(k) O(k) Hard LintCode, πŸ“– Union Find
314 Binary Tree Vertical Order Traversal Python O(n) O(n) Medium πŸ“– BFS
323 Number of Connected Components in an Undirected Graph Python O(n) O(n) Medium πŸ“– Union Find
325 Maximum Size Subarray Sum Equals k Python O(n) O(n) Medium πŸ“–
336 Palindrome Pairs Python O(n * k^2) O(n * k) Hard
340 Longest Substring with At Most K Distinct Characters Python O(n) O(1) Hard πŸ“–
356 Line Reflection Python O(n) O(n) Medium πŸ“– Hash, Two Pointers
387 First Unique Character in a String Python O(n) O(n) Easy
388 Longest Absolute File Path Python O(n) O(d) Medium Stack
409 Longest Palindrome Python O(n) O(1) Easy
424 Longest Repeating Character Replacement Python O(n) O(1) Medium
438 Find All Anagrams in a String Python O(n) O(1) Easy
447 Number of Boomerangs Python O(n^2) O(n) Easy
454 4Sum II Python O(n^2) O(n^2) Medium
473 Matchsticks to Square Python O(n * s * 2^n) O(n * (2^n + s)) Medium
554 Brick Wall Python O(n) O(m) Medium

Data Structure

# Title Solution Time Space Difficulty Tag Note
146 LRU Cache Python O(1) O(k) Hard
225 Implement Stack using Queues Python push: O(n), pop: O(1), top: O(1) O(n) Easy

Math

# Title Solution Time Space Difficulty Tag Note
7 Reverse Integer Python O(1) O(1) Easy
9 Palindrome Number Python O(1) O(1) Easy
12 Integer to Roman Python O(n) O(1) Medium
13 Roman to Integer Python O(n) O(1) Easy
29 Divide Two Integers Python O(1) O(1) Medium
50 Pow(x, n) Python O(1) O(1) Medium
60 Permutation Sequence Python O(n^2) O(n) Medium Cantor Ordering
65 Valid Number Python O(n) O(1) Hard Automata
89 Gray Code Python O(2^n) O(1) Medium
166 Fraction to Recurring Decimal Python O(logn) O(1) Medium
168 Excel Sheet Column Title Python O(logn) O(1) Easy
171 Excel Sheet Column Number Python O(n) O(1) Easy
172 Factorial Trailing Zeroes Python O(1) O(1) Easy
223 Rectangle Area Python O(1) O(1) Easy
233 Number of Digit One Python O(1) O(1) Hard CTCI, LintCode
248 Strobogrammatic Number III Python O(5^(n/2)) O(n) Hard πŸ“–
258 Add Digits Python O(1) O(1) Easy
263 Ugly Number Python O(1) O(1) Easy
292 Nim Game Python O(1) O(1) Easy LintCode
319 Bulb Switcher Python O(1) O(1) Medium
326 Power of Three Python O(1) O(1) Easy
335 Self Crossing Python O(n) O(1) Hard
338 Python O(n) O(n) Medium
343 Integer Break Python O(logn) O(1) Medium Tricky, DP
365 Water and Jug Problem Python O(logn) O(1) Medium Euclidean Algorithm
372 Super Pow Python O(n) O(1) Medium
382 Linked List Random Node Python O(n) O(1) Medium Reservoir Sampling
386 Lexicographical Numbers Python O(n) O(1) Medium
390 Elimination Game Python O(logn) O(1) Medium
391 Perfect Rectangle Python O(n) O(n) Hard
398 Random Pick Index Python O(n) O(1) Medium Reservoir Sampling
400 Nth Digit Python O(logn) O(1) Easy
413 Arithmetic Slices Python O(n) O(1) Medium
423 Reconstruct Original Digits from English Python O(n) O(1) Medium GCJ2016 - Round 1B
441 Arranging Coins Python O(nlogn) O(1) Easy Binary Search
453 Minimum Moves to Equal Array Elements Python O(n) O(1) Easy
458 Poor Pigs Python O(n) O(1) Easy
469 Python O(n) O(1) Medium πŸ“–

Sort

# Title Solution Time Space Difficulty Tag Note
56 Merge Intervals Python O(nlogn) O(1) Hard
57 Insert Interval Python O(n) O(1) Hard
75 Sort Colors Python O(n) O(1) Medium Tri Partition
88 Merge Sorted Array Python O(n) O(1) Easy
147 Insertion Sort List Python O(n^2) O(1) Medium
148 Sort List Python O(nlogn) O(logn) Medium
164 Maximum Gap Python O(n) O(n) Hard Tricky
179 Largest Number Python O(nlogn) O(1) Medium
218 The Skyline Problem Python O(nlogn) O(n) Hard Sort, BST
252 Meeting Rooms Python O(nlogn) O(n) Easy πŸ“–
253 Meeting Rooms II Python O(nlogn) O(n) Medium πŸ“–
274 H-Index Python O(n) O(n) Medium Counting Sort
280 Wiggle Sort Python O(n) O(1) Medium πŸ“–
324 Wiggle Sort II Python O(n) on average O(1) Medium variant of Sort Colors Tri Partition
347 Top K Frequent Elements Python O(n) on average O(n) Medium Quick Select, Heap
406 Queue Reconstruction by Height Python O(n * sqrt(n)) O(n) Medium
451 Sort Characters By Frequency Python O(n) O(n) Medium

Two Pointers

# Title Solution Time Space Difficulty Tag Note
19 Remove Nth Node From End of List Python O(n) O(1) Easy
86 Partition List Python O(n) O(1) Medium
141 Linked List Cycle Python O(n) O(1) Easy
142 Linked List Cycle II Python O(n) O(1) Medium
143 Reorder List Python O(n) O(1) Medium
167 Two Sum II - Input array is sorted Python O(n) O(1) Medium
259 3Sum Smaller Python O(n^2) O(1) Medium πŸ“–, LintCode
283 Move Zeroes Python O(n) O(1) Easy
287 Find the Duplicate Number Python O(n) O(1) Hard Binary Search, Two Pointers
344 Reverse String Python O(n) O(1) Easy
345 Reverse Vowels of a String Python O(n) O(1) Easy
349 Intersection of Two Arrays Python O(m + n) O(min(m, n)) Easy EPI Hash, Binary Search
350 Intersection of Two Arrays II Python O(m + n) O(1) Easy EPI Hash, Binary Search
360 Sort Transformed Array Python O(n) O(1) Medium πŸ“–
457 Python O(n) O(1) Medium

Recursion

# Title Solution Time Space Difficulty Tag Note
95 Unique Binary Search Trees II Python O(4^n / n^(3/2) O(4^n / n^(3/2) Medium
98 Validate Binary Search Tree Python O(n) O(1) Medium
100 Same Tree Python O(n) O(h) Easy
104 Maximum Depth of Binary Tree Python O(n) O(h) Easy
105 Python O(n) O(n) Medium
106 Python O(n) O(n) Medium
108 Python O(n) O(logn) Medium
109 Python O(n) O(logn) Medium
110 Balanced Binary Tree Python O(n) O(h) Easy
111 Minimum Depth of Binary Tree Python O(n) O(h) Easy
114 Flatten Binary Tree to Linked List Python O(n) O(h) Medium
116 Populating Next Right Pointers in Each Node Python O(n) O(1) Medium
124 Binary Tree Maximum Path Sum Python O(n) O(h) Hard
129 Sum Root to Leaf Numbers Python O(n) O(h) Medium
156 Binary Tree Upside Down Python O(n) O(1) Medium πŸ“–
241 Different Ways to Add Parentheses Python O(n * 4^n / n^(3/2)) O(n * 4^n / n^(3/2)) Medium
298 Binary Tree Longest Consecutive Sequence Python O(n) O(h) Medium πŸ“–
327 Python O(nlogn) O(n) Hard
333 Largest BST Subtree Python O(n) O(h) Medium πŸ“–
337 House Robber III Python O(n) O(h) Medium
395 Longest Substring with At Least K Repeating Characters Python O(n) O(1) Medium
404 Sum of Left Leaves Python O(n) O(h) Easy
437 Path Sum III Python O(n) O(h) Easy
549 Binary Tree Longest Consecutive Sequence II Python O(n) O(h) Medium πŸ“–

Binary Search

# Title Solution Time Space Difficulty Tag Note
4 Median of Two Sorted Arrays Python O(log(min(m, n))) O(1) Hard
33 Search in Rotated Sorted Array Python O(logn) O(1) Hard
34 Search for a Range Python O(logn) O(1) Medium
35 Search Insert Position Python O(logn) O(1) Medium
69 Sqrt(x) Python O(logn) O(1) Medium
74 Search a 2D Matrix Python O(logm + logn) O(1) Medium
81 Search in Rotated Sorted Array II Python O(logn) O(1) Medium
153 Find Minimum in Rotated Sorted Array Python O(logn) O(1) Medium
154 Find Minimum in Rotated Sorted Array II Python O(logn) ~ O(n) O(1) Hard
162 Find Peak Element Python O(logn) O(1) Medium
222 Python O((logn)^2) O(1) Medium
275 H-Index II Python O(logn) O(1) Medium Binary Search
278 First Bad Version Python O(logn) O(1) Easy LintCode
300 Longest Increasing Subsequence Python O(nlogn) O(n) Medium CTCI, LintCode Binary Search, DP
302 Smallest Rectangle Enclosing Black Pixels Python O(nlogn) O(1) Hard πŸ“–
354 Russian Doll Envelopes Python O(nlogn) O(1) Hard
363 Max Sum of Rectangle No Larger Than K Python O(min(m, n)^2 * max(m, n) * logn(max(m, n))) O(max(m, n)) Hard
367 Valid Perfect Square Python O(logn) O(1) Medium
374 Guess Number Higher or Lower Python O(logn) O(1) Easy
410 Split Array Largest Sum Python O(nlogs) O(1) Hard
436 Find Right Interval Python O(nlogn) O(n) Medium
475 Heaters Python O((m + n) * logn) O(1) Easy

Binary Search Tree

# Title Solution Time Space Difficulty Tag Note
220 Python O(nlogk) O(k) Medium
230 Kth Smallest Element in a BST Python O(max(h, k)) O(min(h, k)) Medium
235 Lowest Common Ancestor of a Binary Search Tree Python O(h) O(1) Easy EPI
270 Python O(h) O(1) Easy πŸ“–
285 Inorder Successor in BST Python O(h) O(1) Medium πŸ“–
352 Data Stream as Disjoint Intervals Python O(logn) O(n) Hard
449 Serialize and Deserialize BST Python O(n) O(h) Medium
450 Delete Node in a BST Python O(h) O(h) Medium

Breadth-First Search

# Title Solution Time Space Difficulty Tag Note
102 Binary Tree Level Order Traversal 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 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 Python O(|V| + |E|) O(|V| + |E|) Medium πŸ“–
269 Alien Dictionary Python O(n) O(1) Hard πŸ“– Topological Sort, BFS, DFS
286 Walls and Gates Python O(m * n) O(g) Medium πŸ“–
310 Minimum Height Trees Python O(n) O(n) Medium
317 Shortest Distance from All Buildings Python O(k * m * n) O(m * n) Hard πŸ“–
433 Minimum Genetic Mutation Python O(n * b) O(b) Medium
444 Sequence Reconstruction Python O(n * s) O(n) Medium πŸ“– Topological Sort

Depth-First Search

# 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 Python O(n) O(h) Medium EPI
247 Strobogrammatic Number II Python O(n^2 * 5^(n/2)) O(n) Medium πŸ“–
250 Python O(n) O(h) Medium πŸ“–
257 Binary Tree Paths Python O(n * h) O(h) Easy
282 Expression Add Operators Python O(4^n) O(n) Hard
301 Remove Invalid Parentheses Python O(C(n, c)) O(c) Hard
329 Longest Increasing Path in a Matrix Python O(m * n) O(m * n) Hard
332 Reconstruct Itinerary Python O(t! / (n1! * n2! * ... nk!)) O(t) Medium
339 Nested List Weight Sum Python O(n) O(h) Easy πŸ“–
364 Nested List Weight Sum II Python O(n) O(h) Medium πŸ“–
366 Find Leaves of Binary Tree Python O(n) O(h) Medium πŸ“–
399 Evaluate Division Python O(q * |V|!) O(e) Medium
417 Pacific Atlantic Water Flow Python O(m * n) O(m * n) Medium
440 K-th Smallest in Lexicographical Order Python O(logn) O(logn) Hard
464 Python O(n!) O(n) Medium

Backtracking

# Title Solution Time Space Difficulty Tag Note
17 Letter Combinations of a Phone Number Python O(n * 4^n) O(n) Medium
22 Generate Parentheses Python O(4^n / n^(3/2)) O(n) Medium
37 Sudoku Solver Python O((9!)^9) O(1) Hard
39 Combination Sum Python O(k * n^k) O(k) Medium
40 Combination Sum II Python O(k * C(n, k)) O(k) Medium
46 Permutations Python O(n * n!) O(n) Medium
47 Permutations II Python O(n * n!) O(n) Medium
51 N-Queens Python O(n!) O(n) Hard
52 N-Queens-II Python O(n!) O(n) Hard
77 Combinations Python O(n!) O(n) Medium
79 Word Search Python O(m * n * l) O(l) Medium
93 Restore IP Addresses Python O(1) O(1) Medium
78 Subsets Python O(n * 2^n) O(1) Medium
90 Subsets II 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 Python O(n * l^2 + n * r) O(n^2) Hard
212 Word Search II Python O(m * n * l) O(l) Hard LintCode Trie, DFS
216 Python O(k * C(n, k)) O(k) Medium
254 Factor Combinations Python O(nlogn) O(logn) Medium πŸ“–
267 Palindrome Permutation II Python O(n * n!) O(n) Medium πŸ“–
291 Word Pattern II Python O(n * C(n - 1, c - 1)) O(n + c) Hard πŸ“–
294 Flip Game II Python O(n + c^2) O(c) Medium πŸ“– DP, Hash
320 Generalized Abbreviation Python O(n * 2^n) O(n) Medium πŸ“–
425 Word Squares Python O(n^2 * n!) O(n^2) Hard πŸ“–

Dynamic Programming

# Title Solution Time Space Difficulty Tag Note
10 Regular Expression Matching Python O(m * n) O(n) Hard
53 Maximum Subarray Python O(n) O(1) Medium
62 Unique Paths Python O(m * n) O(m + n) Medium
63 Unique Paths II Python O(m * n) O(m + n) Medium
64 Minimum Path Sum Python O(m * n) O(m + n) Medium
70 Climbing Stairs Python O(n) O(1) Easy
72 Edit Distance Python O(m * n) O(m + n) Hard
87 Scramble String Python O(n^4) O(n^3) Hard
91 Decode Ways Python O(n) O(1) Medium
96 Unique Binary Search Trees Python O(n) O(1) Medium Math
97 Interleaving String Python O(m * n) O(m + n) Hard
115 Distinct Subsequences Python O(n^2) O(n) Hard
120 Triangle Python O(m * n) O(n) Medium
123 Best Time to Buy and Sell Stock III Python O(n) O(1) Hard
132 Palindrome Partitioning II Python O(n^2) O(n^2) Hard
139 Word Break Python O(n * l^2) O(n) Medium
152 Maximum Product Subarray Python O(n) O(1) Medium
174 Dungeon Game Python O(m * n) O(m + n) Hard
188 Best Time to Buy and Sell Stock IV Python O(k * n) O(k) Hard
198 House Robber Python O(n) O(1) Easy
213 House Robber II Python O(n) O(1) Medium
221 Maximal Square Python O(n^2) O(n) Medium EPI
256 Paint House Python O(n) O(1) Medium πŸ“–
265 Paint House II Python O(n * k) O(k) Hard πŸ“–
276 Paint Fence Python O(n) O(1) Easy πŸ“–
279 Perfect Squares Python O(n * sqrt(n)) O(n) Medium Hash
303 Range Sum Query - Immutable Python ctor: O(n), lookup: O(1) O(n) Easy
304 Range Sum Query 2D - Immutable Python ctor: O(m * n), lookup: O(1) O(m * n) Medium
309 Best Time to Buy and Sell Stock with Cooldown Python O(n) O(1) Medium
312 Burst Balloons Python O(n^3) O(n^2) Hard
322 Python O(n * k) O(k) Medium
351 Android Unlock Patterns Python O(9^2 * 2^9) O(9 * 2^9) Medium πŸ“– Backtracking
357 Python O(n) O(1) Medium Backtracking, Math
361 Bomb Enemy Python O(m * n) O(m * n) Medium πŸ“–
368 Largest Divisible Subset Python O(n^2) O(n) Medium
375 Guess Number Higher or Lower II Python O(n^2) O(n^2) Medium
377 Python O(nlogn + n * t) O(t) Medium
403 Frog Jump Python O(n) O(n) ~ O(n^2) Hard
416 Partition Equal Subset Sum Python O(n * s) O(s) Medium
418 Sentence Screen Fitting Python O(r + n * c) O(n) Medium πŸ“–
446 Arithmetic Slices II - Subsequence Python O(n^2) O(n * d) Hard
465 Optimal Account Balancing Python O(n * 2^n) O(n * 2^n) Hard πŸ“–
466 Python O(s1 * min(s2, n1)) O(s2) Hard
467 Unique Substrings in Wraparound String Python O(n) O(1) Medium
471 Encode String with Shortest Length Python O(n^3) on average O(n^2) Medium πŸ“–
472 Python O(n * l^2) O(n * l) Medium
474 Ones and Zeroes Python O(s * m * n) O(m * n) Medium

Greedy

# Title Solution Time Space Difficulty Tag Note
11 Python O(n) O(1) Medium
42 Trapping Rain Water Python O(n) O(1) Hard Tricky
44 Wildcard Matching Python O(m + n) O(1) Hard Tricky
45 Jump Game II Python O(n) O(1) Hard
55 Jump Game Python O(n) O(1) Medium
122 Best Time to Buy and Sell Stock II Python O(n) O(1) Medium
134 Gas Station Python O(n) O(1) Medium
135 Python O(n) O(n) Hard
316 Remove Duplicate Letters Python O(n) O(k) Hard Ascending Stack
321 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 Python O(s + logn) O(1) Hard
376 Wiggle Subsequence Python O(n) O(1) Medium
392 Is Subsequence Python O(n) O(1) Medium
397 Integer Replacement Python O(n) O(1) Medium Math
402 Remove K Digits Python O(n) O(n) Medium LintCode
435 Non-overlapping Intervals Python O(nlogn) O(1) Medium
452 Minimum Number of Arrows to Burst Balloons Python O(nlogn) O(1) Medium
455 Assign Cookies Python O(nlogn) O(1) Easy

Design

# Title Solution Time Space Difficulty Tag Note
284 Peeking Iterator Python O(1) O(1) Medium
348 Design Tic-Tac-Toe Python O(1) O(n^2) Medium πŸ“–
353 Design Snake Game Python O(1) O(s) Medium πŸ“– Deque
355 Design Twitter Python O(klogu) O(t + f) Medium LintCode Heap
359 Logger Rate Limiter Python O(1), amortized O(k) Easy πŸ“– Deque
362 Design Hit Counter Python O(1), amortized O(k) Medium πŸ“– Deque
379 Design Phone Directory Python O(1) O(n) Medium πŸ“–
380 Insert Delete GetRandom O(1) Python O(1) O(n) Hard
381 Insert Delete GetRandom O(1) - Duplicates allowed Python O(1) O(n) Hard
432 All O`one Data Structure Python O(1) O(n) Hard
460 LFU Cache Python O(1) O(k) Hard

SQL

# 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

Shell Script

# 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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages