Skip to content

The number of leetcode questions is increasing every week. I will constantly seek and summarize better solutions to the problem and keep updating.

Notifications You must be signed in to change notification settings

OnlyChristmas/leetcode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 

Repository files navigation

The number of leetcode questions is increasing every week.

I will constantly seek and summarize better solutions to the problem and keep updating.


Algorithms

Others


Array

# Title Solution Time Space Difficulty
001 Two Sum Python O(n) O(n) Easy
015 3 Sum Python O(j*k) O(n) Medium
016 3 Sum Closest Python Medium
018 4 Sum Python $O(n^2)$ O(n) Medium
026 Remove Duplicates from Sorted Array Python $O(n^2)$ O(1) Easy
027 Remove Element Python O(n) O(1) Easy
031 Next Permutation Python Medium
035 Search Insert Position Python $O(log_2n)$ O(1) Easy
041 First Missing Positive Python Hard
048 Rotate Image Python O(n$log_2(n)$) O(1) Medium
054 Spiral Matrix Python O(n) O(n) Medium
059 Spiral Matrix II Python O(n) O(1) Medium
066 Plus One Python O(n) O(n) Easy
073 Set Matrix Zeroes Python Medium
080 Remove Duplicates from Sorted Array II Python O(n) O(1) Medium
118 Pascal's Triangle Python O(n) O(n) Easy
119 Pascal's Triangle II Python O(n) O(k) Easy
121 Best Time to Buy and Sell Stock Python O(n) O(1) Easy
128 Longest Consecutive Sequence Python Hard
153 Find Minimum in Rotated Sorted Array Python $O(log_2(n))$ O(1) Medium
154 Find Minimum in Rotated Sorted Array II Python $O(log_2(n))-O(n)$ O(1) Hard
157 Read N Characters Given Read4 Python Easy
158 Read N Characters Given Read4 II - Call multiple times Python Hard
162 Find Peak Element Python $O(log_2(n))$ O(1) Medium
163 Missing Ranges Python Medium
167 Two Sum II - Input array is sorted Python O(n) O(n) Easy
169 Majority Element Python O(n) O(1) Easy
189 Rotate Array Python O(k) O(1) Easy
209 Minimum Size Subarray Sum Python Medium
217 Contains Duplicate Python O(n) O(1) Easy
215 Kth Largest Element in an Array Python O(n) O(1) Medium
228 Summary Ranges Python Medium
229 Majority Element II Python Medium
238 Product of Array Except Self Python Medium
240 Search a 2D Matrix II Python O(n) O(1) Medium
243 Shortest Word Distance Python Easy
245 Shortest Word Distance III Python Medium
251 Flatten 2D Vector Python Medium
268 Missing Number Python O(n) O(1) Medium
277 Find the Celebrity Python Medium
283 Move Zeroes Python O(n) O(1) Easy
289 Game of Life Python Medium
293 Flip Game Python Easy
296 Best Meeting Point Python Hard
311 Sparse Matrix Multiplication Python Medium
334 Increasing Triplet Subsequence Python Medium
370 Range Addition Python Medium
396 Rotate Function Python Easy
412 Fizz Buzz Python O(n) O(n) Easy
414 Third Maximum Number Python Easy
419 Battleships in a Board Python Medium
422 Valid Word Square Python Easy
442 Find All Duplicates in an Array Python Medium
448 Find All Numbers Disappeared in an Array Python O(n) O(1) Easy
485 Max Consecutive Ones Python O(n) O(1) Easy
498 Diagonal Traverse Python O(n) O(n) Medium
531 Lonely Pixel I Python Medium
533 Lonely Pixel II Python Medium
565 Array Nesting Python Medium
566 Reshape the Matrix Python Easy
581 Shortest Unsorted Continuous Subarray Python Easy
605 Can Place Flowers Python Easy
624 Maximum Distance in Arrays Python Easy
643 Maximum Average Subarray I Python Easy
644 Maximum Average Subarray II Python Hard Math
661 Image Smoother Python Easy
665 Non-decreasing Array Python Easy
667 Beautiful Arrangement II Python Medium
670 Maximum Swap Python Medium
674 Longest Continuous Increasing Subsequence Python Easy
683 K Empty Slots Python Hard
697 Degree of an Array Python Easy
713 Subarray Product Less Than K Python Medium
717 1-bit and 2-bit Characters Python Easy
723 Candy Crush Python Medium
724 Find Pivot Index Python O(n) O(1) Easy
729 My Calendar I Python Medium
731 My Calendar II Python Medium
732 My Calendar III Python Hard
747 Largest Number At Least Twice of Others Python O(n) O(1) Easy
755 Pour Water Python Medium
766 Toeplitz Matrix Python Easy
768 Max Chunks To Make Sorted II Python Hard
769 Max Chunks To Make Sorted Python Medium
778 Swim in Rising Water Python Hard
792 Number of Matching Subsequences Python Medium
794 Valid Tic-Tac-Toe State Python Medium
795 Number of Subarrays with Bounded Maximum Python Medium
803 Bricks Falling When Hit Python Hard
807 Max Increase to Keep City Skyline Python Medium
821 Shortest Distance to a Character Python O(n) O(1) Easy
830 Positions of Large Groups Python Easy
832 Flipping an Image Python O($n^2$) O(1) Easy
835 Image Overlap Python Medium
840 Magic Squares In Grid Python Easy
842 Split Array into Fibonacci Sequence Python Medium
845 Longest Mountain in Array Python Medium
849 Maximize Distance to Closest Person Python Easy
860 Lemonade Change Python Easy
868 Transpose Matrix Python Easy
889 Spiral Matrix III Python Medium

Bit Manipulation

# Title Solution Time Space Difficulty
136 Single Number Python O(n) O(1) Easy
137 Single Number II Python O(n) O(1) Medium
169 Majority Element Python $O(nlog_2(n))$ O(1) Easy
190 Reverse Bits Python O(n) O(1) Easy
191 Number of 1 Bits Python O(1)) O(1) Easy
201 Bitwise AND of Numbers Range Python Medium
231 Power of Two Python O(1) O(1) Easy
258 Add Digits Python O(n) O(1) Easy
260 Single Number III Python O(2n) O(1) Medium
268 Missing Number Python O(n) O(1) Medium
318 Maximum Product of Word Lengths Python Medium
338 Counting Bits Python O(n) O(n) Medium
342 Power of Four Python Easy
371 Sum of Two Integers Python Easy
389 Find the Difference Python O(n) O(1) Easy
393 UTF-8 Validation Python Medium
401 Binary Watch Python Easy
411 Minimum Unique Word Abbreviation Python Hard
421 Maximum XOR of Two Numbers in an Array Python Medium
461 Hamming Distance Python O(1) O(1) Easy
462 Minimum Moves to Equal Array Elements II Python Medium
476 Number Complement Python O(1) O(1) Easy
477 Total Hamming Distance Python Medium
645 Set Mismatch Python Easy
693 Binary Number with Alternating Bits Python O(1) O(1) Easy
762 Prime Number of Set Bits in Binary Representation Python Easy
868 Binary Gap Python Easy

String

# Title Solution Time Space Difficulty
005 Longest Palindromic Substring Python Medium
006 ZigZag Conversion Python Easy
008 String to Integer (atoi) Python O(n) O(1) Easy
014 Longest Common Prefix Python $O(n^2)$ O(1) Easy
028 Implement strStr() Python O(n) O(1) Easy
038 Count and Say Python O($n*2^n$) O($2^n$) Easy
043 Multiply Strings Python $O(n^2) O(n) Medium
058 Length of Last Word Python Easy
067 Add Binary Python O(n) O(1) Easy
068 Text Justification Python 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 Medium
165 Compare Version Numbers Python Easy
186 Reverse Words in a String II Python Medium
214 Shortest Palindrome Python Hard
271 Encode and Decode Strings Python Medium
273 Integer to English Words Python Hard
306 Addictive Number Python Medium
345 Reverse Vowels of a String Python O(n) O(1) Easy
383 Ransom Note Python O(n) O(1) Easy
387 First Unique Character in a String Python O(n) O(1) Easy
405 Convert a Number to Hexadecimal Python Easy
408 Valid Word Abbreviation Python Easy
415 Add Strings Python Easy
420 Strong Password Checker Python Hard
434 Number of Segments in a String Python O(n) O(1) Easy
443 String Compression Python Easy
459 Repeated Substring Pattern Python Easy
468 Validate IP Address Python Medium
520 Detect Capital Python O(1) O(1) Easy
521 Longest Uncommon Subsequence I Python Easy
522 Longest Uncommon Subsequence II Python Medium
524 Longest Word in Dictionary through Deleting Python Medium
527 Word Abbreviation Python Hard
539 Minimum Time Difference Python Medium
541 Reverse String II Python O(n) O(1) Easy
551 Student Attendance Record I Python O(1) O(1) Easy
556 Next Greater Element III Python Medium
557 Reverse Words in a String III Python O(n) O(1) Easy
564 Find the Closest Palindrome Python Hard
591 Tag Validator Python Hard
616 Add Bold Tag in String Python Medium
647 Palindromic Substrings Python Medium
648 Replace Words Python Medium
657 Judge Route Circle Python O(1) O(1) Easy
678 Valid Parenthesis String Python Medium
680 Valid Palindrome II Python Easy
681 Next Closest Time Python Medium
686 Repeated String Match Python Easy
696 Count Binary Substrings Python Easy
709 Longest Word in Dictionary Python O(n) O(1) Easy
720 To Lower Case Python Easy
722 Remove Comments Python Medium
751 IP to CIDR Python Medium
758 Bold Words in String Python Easy
791 Custom Sort String Python Medium
796 Rotate String Python O(n) O(1) Easy
804 Unique Morse Code Words Python O(n) O(1) Easy
806 Number of Lines To Write String Python Easy
809 Expressive Words Python Medium
816 Ambiguous Coordinates Python Medium
819 Most Common Word Python O(n) O(1) Easy
820 Short Encoding of Words Python Medium
824 Goat Latin Python O(n) O(1) Easy
831 Masking Personal Information Python Medium
833 Find And Replace in String Python Medium
839 Similar String Groups Python Hard
848 Shifting Letters Python Medium
859 Buddy Strings Python O(n) O(1) Easy

Linked List

# Title Solution Time Space Difficulty
002 Add Two Numbers Python O(n) O(n) Medium
021 Merge Two Sorted Lists Python O(n+m) O(1) Easy
023 Merge k Sorted Lists Python O(nlogk) O(1) Hard
024 Swap Nodes in Pairs Python Easy
025 Reverse Nodes in k-Group Python Hard
061 Rotate List Python O(n) O(1) Medium
082 Remove Duplicates from Sorted List II Python O(n) O(1) Medium
083 Remove Duplicates from Sorted List Python O(n) O(1) Easy
092 Reverse Linked List II Python Medium
138 Copy List with Random Pointer Python O(n) O(1) Medium
160 Intersection of Two Linked Lists Python O(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
328 Odd Even Linked List Python O(n) O(1) Medium
369 Plus One Linked List Python Medium
430 Flatten a Multilevel Doubly Linked List Python O(n) O(1) Meduim
445 Add Two Numbers II Python Medium
725 Split Linked List in Parts Python Medium
817 Linked List Components Python Medium

Stack

# Title Solution Time Space Difficulty
020 Valid Parentheses Python O(n) O(n) Easy
032 Longest Valid Parentheses Python Hard
071 Simplify Path Python Medium
084 Largest Rectangle in Histogram Python Hard
085 Maximal Rectangle Python Hard
101 Symmetric Tree Python O(logn) O(1) Easy
150 Evaluate Reverse Polish Notation Python Medium
173 Binary Search Tree Iterator Python Medium
224 Basic Calculator Python Hard
227 Basic Calculator II Python Medium
232 Implement Queue using Stacks Python —— —— Easy
255 Verify Preorder Sequence in Binary Search Tree Python Medium
272 Closest Binary Search Tree Value II Python Hard
331 Verify Preorder Serialization of a Binary Tree Python Medium
341 Flatten Nested List Iterator Python Medium
385 Mini Parser Python Medium
394 Decode String Python Medium
439 Ternary Expression Parser Python Medium
456 132 Pattern Python Medium
496 Next Greater Element I Python O(n) O(n) Easy
636 Exclusive Time of Functions Python Medium
682 Baseball Game Python Easy
726 Number of Atoms Python Hard
735 Asteroid Collision Python Medium
736 Parse Lisp Expression Python Hard
739 Daily Temperatures Python Medium
770 Basic Calculator IV Python Hard
772 Basic Calculator III Python Hard
853 Car Fleet Python Medium
856 Score of Parentheses Python Medium
872 Leaf-Similar Trees Python Easy

Queue

# Title Solution Time Space Difficulty
239 Sliding Window Maximum Python O(n) O(1) Hard
281 Zigzag Iterator Python Medium
346 Moving Average from Data Stream Python Easy
862 Shortest Subarray with Sum at Least K Python Hard

Heap

# Title Solution Time Space Difficulty
264 Ugly Number II Python Medium
295 Find Median from Data Stream Python Hard
313 Super Ugly Number Python Medium
358 Rearrange String k Distance Apart Python Hard
373 Find K Pairs with Smallest Sums Python Medium
378 Kth Smallest Element in a Sorted Matrix Python Medium
407 Trapping Rain Water II Python Hard
632 Smallest Range Python Hard
846 Hand of Straights Python Medium
855 Exam Room Python Medium
857 Minimum Cost to Hire K Workers Python Hard
871 Minimum Number of Refueling Stops Python Hard

Tree

# Title Solution Time Space Difficulty
094 Binary Tree Inorder Traversal Python O(n) O(1) Medium
099 Recover Binary Search Tree Python Hard
104 Maximum Depth of Binary Tree Python O(n) O(1) Easy
144 Binary Tree Preorder Traversal Python O(n) O(1) Medium
145 Binary Tree Postorder Traversal Python O(n) O(1) Hard
208 Implement Trie (Prefix Tree) Python Medium
211 Add and Search Word - Data structure design Python Medium
226 Invert Binary Tree Python O(logn) O(1) Easy
297 Serialize and Deserialize Binary Tree Python O(logn) O(1) Hard
307 Range Sum Query - Mutable Python Medium
308 Range Sum Query 2D - Mutable Python Hard
315 Count of Smaller Numbers After Self Python O(nlogn) O(n) Hard
525 Contiguous Array Python Medium
529 Minesweeper Python Medium
536 Construct Binary Tree from String Python Medium
538 Convert BST to Greater Tree Python Easy
543 Diameter of Binary Tree Python Easy
545 Boundary of Binary Tree Python Medium
548 Split Array with Equal Sum Python Medium
563 Binary Tree Tilt Python Easy
572 Subtree of Another Tree Python Easy
606 Construct String from Binary Tree Python Easy
617 Merge Two Binary Trees Python Easy
623 Add One Row to Tree Python Medium
637 Average of Levels in Binary Tree Python Easy
652 Find Duplicate Subtrees Python Medium
653 Two Sum IV - Input is a BST Python Easy
654 Maximum Binary Tree Python Medium
655 Print Binary Tree Python Medium
662 Maximum Width of Binary Tree Python Medium
663 Equal Tree Partition Python Medium
677 Map Sum Pairs Python Medium
684 Redundant Connection Python Medium
685 Redundant Connection II Python Hard
687 Longest Univalue Path Python Easy
699 Falling Squares Python Hard
814 Binary Tree Pruning Python Medium
850 Rectangle Area II Python Hard
863 All Nodes Distance K in Binary Tree Python Medium
866 Smallest Subtree with all the Deepest Nodes Python Medium

Hash Table

# Title Solution Time Space Difficulty
001 Two Sum Python O(n) O(n) Easy
003 Longest Substring Without Repeating Characters Python O(n) O(n) Medium
030 Substring with Concatenation of All Words Python Hard
036 Valid Sudoku Python $O(n^2)$ O(n) Medium
049 Group Anagrams Python O(n) O(n) Medium
076 Minimum Window Substring Python Hard
136 Single Number Python O(n) O(1) Easy
149 Max Points on a Line Python $O(n^2)$ O(n) Hard
159 Longest Substring with At Most Two Distinct Characters Python Hard
170 Two Sum III - Data structure design Python Easy
187 Repeated DNA Sequences Python Medium
202 Happy Number Python O(n) O(1) Easy
204 Count Primes Python O(n) O(n) Easy
205 Isomorphic Strings Python O(n) O(1) Easy
217 Contains Duplicate Python O(n) O(1) Easy
219 Contains Duplicate II Python O(n) O(n) Easy
242 Valid Anagram Python O(n) O(1) Easy
244 Shortest Word Distance II Python Medium
246 Strobogrammatic Number Python Easy
249 Group Shifted Strings Python Easy
266 Palindrome Permutation Python Easy
288 Unique Word Abbreviation Python Easy
290 Word Pattern Python Easy
299 Bulls and Cows Python Easy
305 Number of Islands II Python Hard
314 Binary Tree Vertical Order Traversal Python Medium
323 Number of Connected Components in an Undirected Graph Python Medium
325 Maximum Size Subarray Sum Equals k Python Medium
336 Palindrome Pairs Python Hard
340 Longest Substring with At Most K Distinct Characters Python Hard
349 Intersection of Two Arrays Python O(n) O(1) Easy
356 Line Reflection Python Medium
387 First Unique Character in a String Python O(n) O(1) Easy
388 Longest Absolute File Path Python Medium
389 Find the Difference Python O(n) O(1) Easy
409 Longest Palindrome Python Easy
424 Longest Repeating Character Replacement Python Medium
438 Find All Anagrams in a String Python Easy
447 Number of Boomerangs Python O(n^2) O(n) Easy
454 4Sum II Python $O(n^2)$ O(n) Medium
470 Implement Rand10() Using Rand7() Python Medium
473 Matchsticks to Square Python Medium
500 Keyboard Row Python O(n) O(n) Easy
523 Continuous Subarray Sum Python Medium
532 K-diff Pairs in an Array Python Easy
554 Brick Wall Python Medium
560 Subarray Sum Equals K Python Medium
561 Array Partition I Python $O(nlog_2(n))$ O(1) Easy
575 Distribute Candies Python Easy
594 Longest Harmonious Subsequence Python Easy
599 Minimum Index Sum of Two Lists Python Easy
609 Find Duplicate File in System Python Medium
721 Accounts Merge Python Medium
734 Sentence Similarity Python Easy
737 Sentence Similarity II Python Medium
748 Shortest Completing Word Python Easy
760 Find Anagram Mappings Python Easy
771 Jewels and Stones Python O(n) O(1) Easy
811 Subdomain Visit Count Python Easy
822 Card Flipping Game Python Medium
825 Friends Of Appropriate Ages Python Medium
869 Reordered Power of 2 Python Medium
873 Length of Longest Fibonacci Subsequence Python Medium

Math

# Title Solution Time Space Difficulty
007 Reverse Integer Python O(n) O(1) Easy
009 Palindrome Number Python O(1) O(1) Easy
012 Integer to Roman Python Medium
013 Roman to Integer Python O(n) O(1) Easy
026 Remove Duplicates from Sorted Array Python $O(n)$ O(1) Easy
029 Divide Two Integers Python Medium
050 Pow(x, n) Python Medium
060 Permutation Sequence Python Medium
065 Valid Number Python Hard
066 Plus One Python O(n) O(n) Easy
067 Add Binary Python Easy
089 Gray Code Python Medium
166 Fraction to Recurring Decimal Python Medium
168 Excel Sheet Column Title Python Easy
171 Excel Sheet Column Number Python O(n) O(1) Easy
172 Factorial Trailing Zeroes Python O(1) O(1) Easy
202 Happy Number Python O(n) O(1) Easy
204 Count Primes Python O(n) O(n) Easy
223 Rectangle Area Python Easy
231 Power of Two Python O(1) O(1) Easy
233 Number of Digit One Python Hard
248 Strobogrammatic Number III Python Hard
258 Add Digits Python O(n) O(1) Easy
263 Ugly Number Python Easy
268 Missing Number Python O(n) O(1) Medium
292 Nim Game Python O(1) O(1) Easy
319 Bulb Switcher Python Medium
326 Power of Three Python O(1) O(1) Easy
335 Self Crossing Python Hard
343 Integer Break Python Medium
365 Water and Jug Problem Python Medium
367 Valid Perfect Square Python O(1) O(1) Easy
372 Super Pow Python Medium
382 Linked List Random Node Python Medium
386 Lexicographical Numbers Python Medium
390 Elimination Game Python Medium
391 Perfect Rectangle Python Hard
398 Random Pick Index Python Medium
400 Nth Digit Python Easy
413 Arithmetic Slices Python Medium
423 Reconstruct Original Digits from English Python Medium
441 Arranging Coins Python Easy
453 Minimum Moves to Equal Array Elements Python Easy
458 Poor Pigs Python Easy
469 Convex Polygon Python Medium
470 Implement Rand10() Using Rand7() Python Medium
517 Super Washing Machines Python Hard
537 Complex Number Multiplication Python Medium
553 Optimal Division Python Medium
573 Squirrel Simulation Python Medium
593 Valid Square Python Medium
592 Fraction Addition and Subtraction Python Medium
598 Range Addition II Python O(n) O(1) Easy
625 Minimum Factorization Python Medium
628 Maximum Product of Three Numbers Python Easy
633 Sum of Square Numbers Python Easy
634 Find the Derangement of An Array Python Medium
640 Solve the Equation Python Medium
651 4 Keys Keyboard Python Medium
660 Remove 9 Python Hard
672 Bulb Switcher II Python Medium
728 Self Dividing Numbers Python O(n) O(1) Medium
754 Reach a Number Python Medium
775 Global and Local Inversions Python Medium
779 K-th Symbol in Grammar Python Medium
780 Reaching Points Python Hard
781 Rabbits in Forest Python Medium
782 Transform to Chessboard Python Hard
789 Escape The Ghosts Python Medium
800 Similar RGB Color Python Easy
810 Chalkboard XOR Game Python Hard
812 Largest Triangle Area Python Easy
829 Consecutive Numbers Sum Python Medium
836 Rectangle Overlap Python Easy
858 Mirror Reflection Python Medium
867 Prime Palindrome Python Medium
880 Random Pick with Weight Python Medium
881 Random Flip Matrix Python Medium
882 Random Point in Non-overlapping Rectangles Python Medium
883 Generate Random Point in a Circle Python Medium

Sort

# Title Solution Time Space Difficulty
056 Merge Intervals Python O(n) O(1) Medium
057 Insert Interval Python Hard
075 Sort Colors Python O(n) O(1) Medium
088 Merge Sorted Array Python O(n) O(1) Easy
147 Insertion Sort List Python Medium
148 Sort List Python Medium
164 Maximum Gap Python Hard
179 Largest Number Python O(nlogn) O(1) Medium
218 The Skyline Problem Python Hard
242 Valid Anagram Python O(n) O(1) Easy
252 Meeting Rooms Python Easy
253 Meeting Rooms II Python Medium
274 H-Index Python Medium
280 Wiggle Sort Python Medium
324 Wiggle Sort II Python Medium
347 Top K Frequent Elements Python Medium
406 Queue Reconstruction by Height Python Medium
451 Sort Characters By Frequency Python O(nlogn) 1 Medium
692 Top K Frequent Words Python Medium

Two Pointers

# Title Solution Time Space Difficulty
019 Remove Nth Node From End of List Python O(n) O(1) Easy
028 Implement strStr() Python O(n) O(1) Easy
035 Search Insert Position Python $O(log_2(n))$ O(1) Easy
086 Partition List Python Medium
125 Valid Palindrome Python O(n) O(1) Easy
141 Linked List Cycle Python O(n) O(1) Easy
142 Linked List Cycle II Python Medium
143 Reorder List Python Medium
167 Two Sum II - Input array is sorted Python O(n) O(n) Easy
259 3Sum Smaller Python Medium
283 Move Zeroes Python O(n) O(1) Easy
287 Find the Duplicate Number Python Hard
344 Reverse String Python O(n) O(1) Easy
345 Reverse Vowels of a String Python O(n) O(1) Easy
350 Intersection of Two Arrays II Python O(n) O(1) Easy
360 Sort Transformed Array Python Medium
457 Circular Array Loop Python Medium
567 Permutation in String Python Medium
611 Valid Triangle Number Python Medium
777 Swap Adjacent in LR String Python Medium
826 Most Profit Assigning Work Python Medium
828 Unique Letter String Python Hard
844 Backspace String Compare Python Easy
876 Middle of the Linked List Python Easy

Recursion

# Title Solution Time Space Difficulty
095 Unique Binary Search Trees II Python Medium
098 Validate Binary Search Tree Python Medium
100 Same Tree Python Easy
105 Construct Binary Tree from Preorder and Inorder Traversal Python Medium
106 Construct Binary Tree from Inorder and Postorder Traversal Python Medium
108 Convert Sorted Array to Binary Search Tree Python Medium
109 Convert Sorted List to Binary Search Tree Python Medium
110 Balanced Binary Tree Python O(logn) O(1) Easy
111 Minimum Depth of Binary Tree Python Easy
114 Flatten Binary Tree to Linked List Python Medium
116 Populating Next Right Pointers in Each Node Python Medium
124 Binary Tree Maximum Path Sum Python Hard
129 Sum Root to Leaf Numbers Python Medium
156 Binary Tree Upside Down Python Medium
241 Different Ways to Add Parentheses Python Medium
298 Binary Tree Longest Consecutive Sequence Python O(n) O(1) Medium
327 Count of Range Sum Python Hard
333 Largest BST Subtree Python Medium
337 House Robber III Python O(logn) O(1) Medium
395 Longest Substring with At Least K Repeating Characters Python Medium
404 Sum of Left Leaves Python Easy
437 Path Sum III Python Easy
544 Output Contest Matches Python Medium
549 Binary Tree Longest Consecutive Sequence II Python Medium
669 Trim a Binary Search Tree Python Easy
671 Second Minimum Node In a Binary Tree Python Easy
761 Special Binary String Python Hard

Binary Search

# Title Solution Time Space Difficulty
004 Median of Two Sorted Arrays Python O(log(n)) O(1) Hard
033 Search in Rotated Sorted Array Python O(logn) O(1) Medium
034 Search for a Range Python Medium
305 Search Insert Position Python Medium
069 Sqrt(x) Python O(logn) O(1) Easy
074 Search a 2D Matrix Python Medium
081 Search in Rotated Sorted Array II Python O(logn)~O(n) O(1) Medium
153 Find Minimum in Rotated Sorted Array Python $O(log_2(n))$ O(1) Medium
154 Find Minimum in Rotated Sorted Array II Python $O(log_2(n))-O(n)$ O(1) Hard
162 Find Peak Element Python $O(log_2(n))$ O(1) Medium
167 Two Sum II - Input array is sorted Python O(n) O(n) Easy
222 Count Complete Tree Nodes Python Medium
275 H-Index II Python Medium
278 First Bad Version Python $O(log_2(n))$ O(1) Easy
300 Longest Increasing Subsequence Python O(nlogn) O(1)~O(n) Medium
302 Smallest Rectangle Enclosing Black Pixels Python Hard
354 Russian Doll Envelopes Python Hard
363 Max Sum of Rectangle No Larger Than K Python Hard
367 Valid Perfect Square Python O(1) O(1) Easy
374 Guess Number Higher or Lower Python Easy
410 Split Array Largest Sum Python Hard
436 Find Right Interval Python Medium
475 Heaters Python Easy
540 Single Element in a Sorted Array Python Medium
658 Find K Closest Elements Python Medium
668 Kth Smallest Number in Multiplication Table Python O(min(m,n)log(m*n)) O(1) Hard
704 Binary Search Python O(nlogn) O(1) Easy
719 Find K-th Smallest Pair Distance Python Hard
744 Find Smallest Letter Greater Than Target Python $O(log_2(n))$ O(1) Easy
774 Minimize Max Distance to Gas Station Python Hard
786 K-th Smallest Prime Fraction Python Hard
793 Preimage Size of Factorial Zeroes Function Python Hard
852 Peak Index in a Mountain Array Python O($lon_2(n)$) O(1) Easy
864 Random Pick with Blacklist Python Hard
875 Koko Eating Bananas Python Medium
878 Nth Magical Number Python Hard

Binary Search Tree

# Title Solution Time Space Difficulty
220 Contains Duplicate III Python $O(n^2)$ O(1) Medium
230 Kth Smallest Element in a BST Python O(logn) O(n) Medium
235 Lowest Common Ancestor of a Binary Search Tree Python O(n) O(1) Easy
270 Closest Binary Search Tree Value Python Easy
285 Inorder Successor in BST Python Medium
352 Data Stream as Disjoint Intervals Python Hard
449 Serialize and Deserialize BST Python Medium
450 Delete Node in a BST Python Medium
530 Minimum Absolute Difference in BST Python Easy
776 Split BST Python Medium
783 Minimum Distance Between BST Nodes Python Easy

Breadth-First Search

# Title Solution Time Space Difficulty
102 Binary Tree Level Order Traversal Python O(n) O(n) Medium
107 Binary Tree Level Order Traversal II Python Easy
103 Binary Tree Zigzag Level Order Traversal Python Medium
117 Populating Next Right Pointers in Each Node II Python Hard
127 Word Ladder Python Medium
130 Surrounded Regions Python Medium
133 Clone Graph Python Medium
207 Course Schedule Python + \
210 Course Schedule II Python + \
261 Graph Valid Tree Python + \
269 Alien Dictionary Python Hard
286 Walls and Gates Python Medium
310 Minimum Height Trees Python Medium
317 Shortest Distance from All Buildings Python Hard
433 Minimum Genetic Mutation Python Medium
444 Sequence Reconstruction Python Medium
542 01 Matrix Python Medium
666 Path Sum IV Python Medium
675 Cut Off Trees for Golf Event Python Hard
742 Closest Leaf in a Binary Tree Python Medium
743 Network Delay Time Python * log\
752 Open the Lock Python Medium
773 Sliding Puzzle Python Hard
787 Cheapest Flights Within K Stops Python * log\
815 Bus Routes Python + \
854 K-Similar Strings Python Hard
865 Shortest Path to Get All Keys Python Hard

Depth-First Search

# Title Solution Time Space Difficulty
104 Maximum Depth of Binary Tree Python O(n) O(1) Easy
112 Path Sum Python O(n) O(1) Easy
113 Path Sum II Python Medium
199 Binary Tree Right Side View Python Medium
200 Number of Islands Python Medium
236 Lowest Common Ancestor of a Binary Tree Python Medium
247 Strobogrammatic Number II Python Medium
250 Count Univalue Subtrees Python Medium
257 Binary Tree Paths Python Easy
282 Expression Add Operators Python Hard
301 Remove Invalid Parentheses Python Hard
329 Longest Increasing Path in a Matrix Python Hard
332 Reconstruct Itinerary Python Medium
339 Nested List Weight Sum Python Easy
364 Nested List Weight Sum II Python Medium
366 Find Leaves of Binary Tree Python Medium
399 Evaluate Division Python !)_
417 Pacific Atlantic Water Flow Python Medium
440 K-th Smallest in Lexicographical Order Python Hard
464 Can I Win Python Medium
515 Find Largest Value in Each Tree Row Python Medium
547 Friend Circles Python Medium
582 Kill Process Python Medium
638 Shopping Offers Python Medium
690 Employee Importance Python Easy
694 Number of Distinct Islands Python Medium
695 Max Area of Island Python Easy
711 Number of Distinct Islands II Python Hard
733 Max Area of Island Python Easy
749 Contain Virus Python Hard
753 Cracking the Safe Python Hard
756 Pyramid Transition Matrix Python Medium
785 Is Graph Bipartite? Python + \
797 All Paths From Source to Target Python Medium
802 Find Eventual Safe States Python + \
827 Making A Large Island Python Hard
834 Sum of Distances in Tree Python Hard
841 Keys and Rooms Python Medium
851 Loud and Rich Python Medium

Backtracking

# Title Solution Time Space Difficulty
017 Letter Combinations of a Phone Number Python Medium
022 Generate Parentheses Python Medium
037 Sudoku Solver Python Hard
039 Combination Sum Python Medium
040 Combination Sum II Python Medium
046 Permutations Python Medium
047 Permutations II Python Medium
051 N-Queens Python Hard
052 N-Queens-II Python Hard
077 Combinations Python Medium
078 Subsets Python O(n2) O(1) Medium
079 Word Search Python Medium
090 Subsets II Python O(n^2) O(1) Medium
093 Restore IP Addresses Python Medium
126 Word Ladder II Python Hard
131 Palindrome Partitioning Python Medium
140 Word Break II Python Hard
212 Word Search II Python Hard
216 Combination Sum III Python Medium
254 Factor Combinations Python Medium
267 Palindrome Permutation II Python Medium
291 Word Pattern II Python Hard
294 Flip Game II Python Medium
320 Generalized Abbreviation Python Medium
425 Word Squares Python Hard
526 Beautiful Arrangement Python Medium
676 Implement Magic Dictionary Python Medium
679 24 Game Python Hard
698 Partition to K Equal Sum Subsets Python Medium
718 Maximum Length of Repeated Subarray Python Medium
784 Letter Case Permutation Python Easy

Dynamic Programming

# Title Solution Time Space Difficulty
010 Regular Expression Matching Python Hard
053 Maximum Subarray Python O(n) O(1) Easy
062 Unique Paths Python O(n*m) O(n) Medium
063 Unique Paths II Python Medium
064 Minimum Path Sum Python O(n^2) O(1) Medium
070 Climbing Stairs Python O(n) O(1) Easy
072 Edit Distance Python O(m*n) O(m)/O(n) Hard
087 Scramble String Python Hard
091 Decode Ways Python O(n) O(1) Medium
096 Unique Binary Search Trees Python O(n^2) O(n) Medium
097 Interleaving String Python Hard
115 Distinct Subsequences Python Hard
120 Triangle Python O(n^2) O(1) Medium
123 Best Time to Buy and Sell Stock III Python Hard
121 Best Time to Buy and Sell Stock Python O(n) O(1) Easy
132 Palindrome Partitioning II Python Hard
139 Word Break Python Medium
152 Maximum Product Subarray Python Medium
174 Dungeon Game Python Hard
188 Best Time to Buy and Sell Stock IV Python Hard
198 House Robber Python O(n) O(1) Easy
213 House Robber II Python O(n) O(1) Medium
221 Maximal Square Python Medium
256 Paint House Python Medium
265 Paint House II Python Hard
276 Paint Fence Python Easy
279 Perfect Squares Python O(log_2n) O(1) Medium
303 Range Sum Query - Immutable Python Easy
304 Range Sum Query 2D - Immutable Python Medium
309 Best Time to Buy and Sell Stock with Cooldown Python Medium
312 Burst Balloons Python Hard
322 Coin Change Python Medium
338 Counting Bits Python O(n) O(n) Medium
351 Android Unlock Patterns Python Medium
357 Count Numbers with Unique Digits Python Medium
361 Bomb Enemy Python Medium
368 Largest Divisible Subset Python Medium
375 Guess Number Higher or Lower II Python Medium
377 Combination Sum IV Python Medium
416 Partition Equal Subset Sum Python Medium
403 Frog Jump Python Hard
418 Sentence Screen Fitting Python Medium
446 Arithmetic Slices II - Subsequence Python Hard
465 Optimal Account Balancing Python Hard
466 Count The Repetitions Python Hard
467 Unique Substrings in Wraparound String Python Medium
471 Encode String with Shortest Length Python Medium
472 Concatenated Words Python Medium
474 Ones and Zeroes Python Medium
486 Predict the Winner Python Medium
514 Freedom Trail Python Hard
516 Longest Palindromic Subsequence Python Medium
546 Remove Boxes Python Hard
552 Student Attendance Record II Python Hard
562 Longest Line of Consecutive One in Matrix Python Medium
568 Maximum Vacation Days Python Hard
576 Out of Boundary Paths Python Medium
583 Delete Operation for Two Strings Python Medium
600 Non-negative Integers without Consecutive Ones Python Hard
629 K Inverse Pairs Array Python Hard
639 Decode Ways II Python Hard
650 2 Keys Keyboard Python Medium
656 Coin Path Python Hard
664 Strange Printer Python Hard
673 Number of Longest Increasing Subsequence Python Medium
688 Knight Probability in Chessboard Python Medium
689 Maximum Sum of 3 Non-Overlapping Subarrays Python Hard
691 Stickers to Spell Word Python Hard
712 Minimum ASCII Delete Sum for Two Strings Python Medium
714 Best Time to Buy and Sell Stock with Transaction Fee Python Medium
727 Minimum Window Subsequence Python Hard
730 Count Different Palindromic Subsequences Python Hard
740 Delete and Earn Python Medium
741 Cherry Pickup Python Hard
746 Min Cost Climbing Stairs Python Easy
764 Largest Plus Sign Python Medium
750 Number Of Corner Rectangles Python Medium
788 Rotated Digits Python O(n) O(1) Easy
790 Domino and Tromino Tiling Python Medium
799 Champagne Tower Python Medium
801 Minimum Swaps To Make Sequences Increasing Python Medium
805 Split Array With Same Average Python Hard
808 Soup Servings Python Medium
813 Largest Sum of Averages Python Medium
818 Race Car Python Hard
823 Binary Trees With Factors Python Medium
837 New 21 Game Python Medium
838 Push Dominoes Python Medium
847 Shortest Path Visiting All Nodes Python Hard
877 Stone Game Python O(n) O(1) Medium
879 Profitable Schemes Python

Greedy

# Title Solution Time Space Difficulty
011 Container With Most Water Python O(n) O(1) Medium
042 Trapping Rain Water Python Hard
044 Wildcard Matching Python Hard
045 Jump Game II Python Hard
055 Jump Game Python Medium
122 Best Time to Buy and Sell Stock II Python O(n) O(1) Easy
134 Gas Station Python Medium
135 Candy Python Hard
316 Remove Duplicate Letters Python Hard
321 Create Maximum Number Python Hard
330 Patching Array Python Hard
376 Wiggle Subsequence Python Medium
392 Is Subsequence Python Medium
397 Integer Replacement Python Medium
402 Remove K Digits Python Medium
435 Non-overlapping Intervals Python Medium
452 Minimum Number of Arrows to Burst Balloons Python Medium
455 Assign Cookies Python Easy
621 Task Scheduler Python Medium
630 Course Schedule III Python Hard
646 Maximum Length of Pair Chain Python Medium
649 Dota2 Senate Python Medium
659 Split Array into Consecutive Subsequences Python Medium
738 Monotone Increasing Digits Python Medium
757 Set Intersection Size At Least Two Python Hard
759 Employee Free Time Python Hard
763 Partition Labels Python Medium
767 Reorganize String Python Medium
798 Smallest Rotation with Highest Score Python Hard
843 Guess the Word Python Hard
861 Score After Flipping Matrix Python Medium
870 Advantage Shuffle Python Medium

Graph

# Title Solution Time Space Difficulty
765 Couples Holding Hands Python Hard

Geometry

# Title Solution Time Space Difficulty
587 Erect the Fence Python Hard

Simulation

# Title Solution Time Space Difficulty
874 Walking Robot Simulation Python Easy

Design

# Title Solution Time Space Difficulty
146 LRU Cache Python Hard
155 Min Stack Python ---- ---- Easy
225 Implement Stack using Queues Python _ _ Easy
284 Peeking Iterator Python Medium
348 Design Tic-Tac-Toe Python Medium
353 Design Snake Game Python Medium
355 Design Twitter Python Medium
359 Logger Rate Limiter Python Easy
362 Design Hit Counter Python Medium
379 Design Phone Directory Python Medium
380 Insert Delete GetRandom O(1) Python Hard
381 Insert Delete GetRandom O(1) - Duplicates allowed Python Hard
384 Shuffle an Array Python O(n) O(1) Medium
432 All O`one Data Structure Python Hard
460 LFU Cache Python Hard
535 Encode and Decode TinyURL Python Medium
588 Design In-Memory File System Python Hard
604 Design Compressed String Iterator Python Easy
622 Design Circular Queue Python Medium
631 Design Excel Sum Formula Python Hard
635 Design Log Storage System Python Medium
642 Design Search Autocomplete System Python Hard
707 Design Linked List Python - - Easy
715 Range Module Python Hard
716 Max Stack Python Easy
745 Prefix and Suffix Search Python Hard

Divide and Conquer

# Title Solution Time Space Difficulty
169 Majority Element Python $O(nlog_2(n))$ O(1) Easy

SQL

# Title Solution Difficulty
175 Combine Two Tables MySQL Easy
176 Second Highest Salary MySQL Easy
177 Nth Highest Salary MySQL Medium
178 Rank Scores MySQL Medium
180 Consecutive Numbers MySQL Medium
181 Employees Earning More Than Their Managers MySQL Easy
182 Duplicate Emails MySQL Easy
183 Customers Who Never Order MySQL Easy
184 Department Highest Salary MySQL Medium
185 Department Top Three Salaries MySQL Hard
196 Delete Duplicate Emails MySQL Easy
197 Rising Temperature MySQL Easy
262 Trips and Users MySQL Hard
595 Big Countries MySQL Easy
620 Not Boring Movies MySQL Easy
627 Swap Salary MySQL Easy

Shell Script

# Title Solution Difficulty
192 Word Frequency Shell Medium
193 Valid Phone Numbers Shell Easy
194 Transpose File Shell Medium
195 Tenth Line Shell Easy

About

The number of leetcode questions is increasing every week. I will constantly seek and summarize better solutions to the problem and keep updating.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published