Skip to content

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

#TitleSolutionTimeSpaceDifficulty
001Two SumPythonO(n)O(n)Easy
0153 SumPythonO(j*k)O(n)Medium
0163 Sum ClosestPythonMedium
0184 SumPython$O(n^2)$O(n)Medium
026Remove Duplicates from Sorted ArrayPython$O(n^2)$O(1)Easy
027Remove ElementPythonO(n)O(1)Easy
031Next PermutationPythonMedium
035Search Insert PositionPython$O(log_2n)$O(1)Easy
041First Missing PositivePythonHard
048Rotate ImagePythonO(n$log_2(n)$)O(1)Medium
054Spiral MatrixPythonO(n)O(n)Medium
059Spiral Matrix IIPythonO(n)O(1)Medium
066Plus OnePythonO(n)O(n)Easy
073Set Matrix ZeroesPythonMedium
080Remove Duplicates from Sorted Array IIPythonO(n)O(1)Medium
118Pascal's TrianglePythonO(n)O(n)Easy
119Pascal's Triangle IIPythonO(n)O(k)Easy
121Best Time to Buy and Sell StockPythonO(n)O(1)Easy
128Longest Consecutive SequencePythonHard
153Find Minimum in Rotated Sorted ArrayPython$O(log_2(n))$O(1)Medium
154Find Minimum in Rotated Sorted Array IIPython$O(log_2(n))-O(n)$O(1)Hard
157Read N Characters Given Read4PythonEasy
158Read N Characters Given Read4 II - Call multiple timesPythonHard
162Find Peak ElementPython$O(log_2(n))$O(1)Medium
163Missing RangesPythonMedium
167Two Sum II - Input array is sortedPythonO(n)O(n)Easy
169Majority ElementPythonO(n)O(1)Easy
189Rotate ArrayPythonO(k)O(1)Easy
209Minimum Size Subarray SumPythonMedium
217Contains DuplicatePythonO(n)O(1)Easy
215Kth Largest Element in an ArrayPythonO(n)O(1)Medium
228Summary RangesPythonMedium
229Majority Element IIPythonMedium
238Product of Array Except SelfPythonMedium
240Search a 2D Matrix IIPythonO(n)O(1)Medium
243Shortest Word DistancePythonEasy
245Shortest Word Distance IIIPythonMedium
251Flatten 2D VectorPythonMedium
268Missing NumberPythonO(n)O(1)Medium
277Find the CelebrityPythonMedium
283Move ZeroesPythonO(n)O(1)Easy
289Game of LifePythonMedium
293Flip GamePythonEasy
296Best Meeting PointPythonHard
311Sparse Matrix MultiplicationPythonMedium
334Increasing Triplet SubsequencePythonMedium
370Range AdditionPythonMedium
396Rotate FunctionPythonEasy
412Fizz BuzzPythonO(n)O(n)Easy
414Third Maximum NumberPythonEasy
419Battleships in a BoardPythonMedium
422Valid Word SquarePythonEasy
442Find All Duplicates in an ArrayPythonMedium
448Find All Numbers Disappeared in an ArrayPythonO(n)O(1)Easy
485Max Consecutive OnesPythonO(n)O(1)Easy
498Diagonal TraversePythonO(n)O(n)Medium
531Lonely Pixel IPythonMedium
533Lonely Pixel IIPythonMedium
565Array NestingPythonMedium
566Reshape the MatrixPythonEasy
581Shortest Unsorted Continuous SubarrayPythonEasy
605Can Place FlowersPythonEasy
624Maximum Distance in ArraysPythonEasy
643Maximum Average Subarray IPythonEasy
644Maximum Average Subarray IIPythonHard Math
661Image SmootherPythonEasy
665Non-decreasing ArrayPythonEasy
667Beautiful Arrangement IIPythonMedium
670Maximum SwapPythonMedium
674Longest Continuous Increasing SubsequencePythonEasy
683K Empty SlotsPythonHard
697Degree of an ArrayPythonEasy
713Subarray Product Less Than KPythonMedium
7171-bit and 2-bit CharactersPythonEasy
723Candy CrushPythonMedium
724Find Pivot IndexPythonO(n)O(1)Easy
729My Calendar IPythonMedium
731My Calendar IIPythonMedium
732My Calendar IIIPythonHard
747Largest Number At Least Twice of OthersPythonO(n)O(1)Easy
755Pour WaterPythonMedium
766Toeplitz MatrixPythonEasy
768Max Chunks To Make Sorted IIPythonHard
769Max Chunks To Make SortedPythonMedium
778Swim in Rising WaterPythonHard
792Number of Matching SubsequencesPythonMedium
794Valid Tic-Tac-Toe StatePythonMedium
795Number of Subarrays with Bounded MaximumPythonMedium
803Bricks Falling When HitPythonHard
807Max Increase to Keep City SkylinePythonMedium
821Shortest Distance to a CharacterPythonO(n)O(1)Easy
830Positions of Large GroupsPythonEasy
832Flipping an ImagePythonO($n^2$)O(1)Easy
835Image OverlapPythonMedium
840Magic Squares In GridPythonEasy
842Split Array into Fibonacci SequencePythonMedium
845Longest Mountain in ArrayPythonMedium
849Maximize Distance to Closest PersonPythonEasy
860Lemonade ChangePythonEasy
868Transpose MatrixPythonEasy
889Spiral Matrix IIIPythonMedium

Bit Manipulation

#TitleSolutionTimeSpaceDifficulty
136Single NumberPythonO(n)O(1)Easy
137Single Number IIPythonO(n)O(1)Medium
169Majority ElementPython$O(nlog_2(n))$O(1)Easy
190Reverse BitsPythonO(n)O(1)Easy
191Number of 1 BitsPythonO(1))O(1)Easy
201Bitwise AND of Numbers RangePythonMedium
231Power of TwoPythonO(1)O(1)Easy
258Add DigitsPythonO(n)O(1)Easy
260Single Number IIIPythonO(2n)O(1)Medium
268Missing NumberPythonO(n)O(1)Medium
318Maximum Product of Word LengthsPythonMedium
338Counting BitsPythonO(n)O(n)Medium
342Power of FourPythonEasy
371Sum of Two IntegersPythonEasy
389Find the DifferencePythonO(n)O(1)Easy
393UTF-8 ValidationPythonMedium
401Binary WatchPythonEasy
411Minimum Unique Word AbbreviationPythonHard
421Maximum XOR of Two Numbers in an ArrayPythonMedium
461Hamming DistancePythonO(1)O(1)Easy
462Minimum Moves to Equal Array Elements IIPythonMedium
476Number ComplementPythonO(1)O(1)Easy
477Total Hamming DistancePythonMedium
645Set MismatchPythonEasy
693Binary Number with Alternating BitsPythonO(1)O(1)Easy
762Prime Number of Set Bits in Binary RepresentationPythonEasy
868Binary GapPythonEasy

String

#TitleSolutionTimeSpaceDifficulty
005Longest Palindromic SubstringPythonMedium
006ZigZag ConversionPythonEasy
008String to Integer (atoi)PythonO(n)O(1)Easy
014Longest Common PrefixPython$O(n^2)$O(1)Easy
028Implement strStr()PythonO(n)O(1)Easy
038Count and SayPythonO($n*2^n$)O($2^n$)Easy
043Multiply StringsPython$O(n^2)O(n)Medium
058Length of Last WordPythonEasy
067Add BinaryPythonO(n)O(1)Easy
068Text JustificationPythonHard
125Valid PalindromePythonO(n)O(1)Easy
151Reverse Words in a StringPythonO(n)O(1)Medium
161One Edit DistancePythonMedium
165Compare Version NumbersPythonEasy
186Reverse Words in a String IIPythonMedium
214Shortest PalindromePythonHard
271Encode and Decode StringsPythonMedium
273Integer to English WordsPythonHard
306Addictive NumberPythonMedium
345Reverse Vowels of a StringPythonO(n)O(1)Easy
383Ransom NotePythonO(n)O(1)Easy
387First Unique Character in a StringPythonO(n)O(1)Easy
405Convert a Number to HexadecimalPythonEasy
408Valid Word AbbreviationPythonEasy
415Add StringsPythonEasy
420Strong Password CheckerPythonHard
434Number of Segments in a StringPythonO(n)O(1)Easy
443String CompressionPythonEasy
459Repeated Substring PatternPythonEasy
468Validate IP AddressPythonMedium
520Detect CapitalPythonO(1)O(1)Easy
521Longest Uncommon Subsequence IPythonEasy
522Longest Uncommon Subsequence IIPythonMedium
524Longest Word in Dictionary through DeletingPythonMedium
527Word AbbreviationPythonHard
539Minimum Time DifferencePythonMedium
541Reverse String IIPythonO(n)O(1)Easy
551Student Attendance Record IPythonO(1)O(1)Easy
556Next Greater Element IIIPythonMedium
557Reverse Words in a String IIIPythonO(n)O(1)Easy
564Find the Closest PalindromePythonHard
591Tag ValidatorPythonHard
616Add Bold Tag in StringPythonMedium
647Palindromic SubstringsPythonMedium
648Replace WordsPythonMedium
657Judge Route CirclePythonO(1)O(1)Easy
678Valid Parenthesis StringPythonMedium
680Valid Palindrome IIPythonEasy
681Next Closest TimePythonMedium
686Repeated String MatchPythonEasy
696Count Binary SubstringsPythonEasy
709Longest Word in DictionaryPythonO(n)O(1)Easy
720To Lower CasePythonEasy
722Remove CommentsPythonMedium
751IP to CIDRPythonMedium
758Bold Words in StringPythonEasy
791Custom Sort StringPythonMedium
796Rotate StringPythonO(n)O(1)Easy
804Unique Morse Code WordsPythonO(n)O(1)Easy
806Number of Lines To Write StringPythonEasy
809Expressive WordsPythonMedium
816Ambiguous CoordinatesPythonMedium
819Most Common WordPythonO(n)O(1)Easy
820Short Encoding of WordsPythonMedium
824Goat LatinPythonO(n)O(1)Easy
831Masking Personal InformationPythonMedium
833Find And Replace in StringPythonMedium
839Similar String GroupsPythonHard
848Shifting LettersPythonMedium
859Buddy StringsPythonO(n)O(1)Easy

Linked List

#TitleSolutionTimeSpaceDifficulty
002Add Two NumbersPythonO(n)O(n)Medium
021Merge Two Sorted ListsPythonO(n+m)O(1)Easy
023Merge k Sorted ListsPythonO(nlogk)O(1)Hard
024Swap Nodes in PairsPythonEasy
025Reverse Nodes in k-GroupPythonHard
061Rotate ListPythonO(n)O(1)Medium
082Remove Duplicates from Sorted List IIPythonO(n)O(1)Medium
083Remove Duplicates from Sorted ListPythonO(n)O(1)Easy
092Reverse Linked List IIPythonMedium
138Copy List with Random PointerPythonO(n)O(1)Medium
160Intersection of Two Linked ListsPythonO(n)O(1)Easy
203Remove Linked List ElementsPythonO(n)O(1)Easy
206Reverse Linked ListPythonO(n)O(1)Easy
234Palindrome Linked ListPythonO(n)O(1)Easy
237Delete Node in a Linked ListPythonO(1)O(1)Easy
328Odd Even Linked ListPythonO(n)O(1)Medium
369Plus One Linked ListPythonMedium
430Flatten a Multilevel Doubly Linked ListPythonO(n)O(1)Meduim
445Add Two Numbers IIPythonMedium
725Split Linked List in PartsPythonMedium
817Linked List ComponentsPythonMedium

Stack

#TitleSolutionTimeSpaceDifficulty
020Valid ParenthesesPythonO(n)O(n)Easy
032Longest Valid ParenthesesPythonHard
071Simplify PathPythonMedium
084Largest Rectangle in HistogramPythonHard
085Maximal RectanglePythonHard
101Symmetric TreePythonO(logn)O(1)Easy
150Evaluate Reverse Polish NotationPythonMedium
173Binary Search Tree IteratorPythonMedium
224Basic CalculatorPythonHard
227Basic Calculator IIPythonMedium
232Implement Queue using StacksPython————Easy
255Verify Preorder Sequence in Binary Search TreePythonMedium
272Closest Binary Search Tree Value IIPythonHard
331Verify Preorder Serialization of a Binary TreePythonMedium
341Flatten Nested List IteratorPythonMedium
385Mini ParserPythonMedium
394Decode StringPythonMedium
439Ternary Expression ParserPythonMedium
456132 PatternPythonMedium
496Next Greater Element IPythonO(n)O(n)Easy
636Exclusive Time of FunctionsPythonMedium
682Baseball GamePythonEasy
726Number of AtomsPythonHard
735Asteroid CollisionPythonMedium
736Parse Lisp ExpressionPythonHard
739Daily TemperaturesPythonMedium
770Basic Calculator IVPythonHard
772Basic Calculator IIIPythonHard
853Car FleetPythonMedium
856Score of ParenthesesPythonMedium
872Leaf-Similar TreesPythonEasy

Queue

#TitleSolutionTimeSpaceDifficulty
239Sliding Window MaximumPythonO(n)O(1)Hard
281Zigzag IteratorPythonMedium
346Moving Average from Data StreamPythonEasy
862Shortest Subarray with Sum at Least KPythonHard

Heap

#TitleSolutionTimeSpaceDifficulty
264Ugly Number IIPythonMedium
295Find Median from Data StreamPythonHard
313Super Ugly NumberPythonMedium
358Rearrange String k Distance ApartPythonHard
373Find K Pairs with Smallest SumsPythonMedium
378Kth Smallest Element in a Sorted MatrixPythonMedium
407Trapping Rain Water IIPythonHard
632Smallest RangePythonHard
846Hand of StraightsPythonMedium
855Exam RoomPythonMedium
857Minimum Cost to Hire K WorkersPythonHard
871Minimum Number of Refueling StopsPythonHard

Tree

#TitleSolutionTimeSpaceDifficulty
094Binary Tree Inorder TraversalPythonO(n)O(1)Medium
099Recover Binary Search TreePythonHard
104Maximum Depth of Binary TreePythonO(n)O(1)Easy
144Binary Tree Preorder TraversalPythonO(n)O(1)Medium
145Binary Tree Postorder TraversalPythonO(n)O(1)Hard
208Implement Trie (Prefix Tree)PythonMedium
211Add and Search Word - Data structure designPythonMedium
226Invert Binary TreePythonO(logn)O(1)Easy
297Serialize and Deserialize Binary TreePythonO(logn)O(1)Hard
307Range Sum Query - MutablePythonMedium
308Range Sum Query 2D - MutablePythonHard
315Count of Smaller Numbers After SelfPythonO(nlogn)O(n)Hard
525Contiguous ArrayPythonMedium
529MinesweeperPythonMedium
536Construct Binary Tree from StringPythonMedium
538Convert BST to Greater TreePythonEasy
543Diameter of Binary TreePythonEasy
545Boundary of Binary TreePythonMedium
548Split Array with Equal SumPythonMedium
563Binary Tree TiltPythonEasy
572Subtree of Another TreePythonEasy
606Construct String from Binary TreePythonEasy
617Merge Two Binary TreesPythonEasy
623Add One Row to TreePythonMedium
637Average of Levels in Binary TreePythonEasy
652Find Duplicate SubtreesPythonMedium
653Two Sum IV - Input is a BSTPythonEasy
654Maximum Binary TreePythonMedium
655Print Binary TreePythonMedium
662Maximum Width of Binary TreePythonMedium
663Equal Tree PartitionPythonMedium
677Map Sum PairsPythonMedium
684Redundant ConnectionPythonMedium
685Redundant Connection IIPythonHard
687Longest Univalue PathPythonEasy
699Falling SquaresPythonHard
814Binary Tree PruningPythonMedium
850Rectangle Area IIPythonHard
863All Nodes Distance K in Binary TreePythonMedium
866Smallest Subtree with all the Deepest NodesPythonMedium

Hash Table

#TitleSolutionTimeSpaceDifficulty
001Two SumPythonO(n)O(n)Easy
003Longest Substring Without Repeating CharactersPythonO(n)O(n)Medium
030Substring with Concatenation of All WordsPythonHard
036Valid SudokuPython$O(n^2)$O(n)Medium
049Group AnagramsPythonO(n)O(n)Medium
076Minimum Window SubstringPythonHard
136Single NumberPythonO(n)O(1)Easy
149Max Points on a LinePython$O(n^2)$O(n)Hard
159Longest Substring with At Most Two Distinct CharactersPythonHard
170Two Sum III - Data structure designPythonEasy
187Repeated DNA SequencesPythonMedium
202Happy NumberPythonO(n)O(1)Easy
204Count PrimesPythonO(n)O(n)Easy
205Isomorphic StringsPythonO(n)O(1)Easy
217Contains DuplicatePythonO(n)O(1)Easy
219Contains Duplicate IIPythonO(n)O(n)Easy
242Valid AnagramPythonO(n)O(1)Easy
244Shortest Word Distance IIPythonMedium
246Strobogrammatic NumberPythonEasy
249Group Shifted StringsPythonEasy
266Palindrome PermutationPythonEasy
288Unique Word AbbreviationPythonEasy
290Word PatternPythonEasy
299Bulls and CowsPythonEasy
305Number of Islands IIPythonHard
314Binary Tree Vertical Order TraversalPythonMedium
323Number of Connected Components in an Undirected GraphPythonMedium
325Maximum Size Subarray Sum Equals kPythonMedium
336Palindrome PairsPythonHard
340Longest Substring with At Most K Distinct CharactersPythonHard
349Intersection of Two ArraysPythonO(n)O(1)Easy
356Line ReflectionPythonMedium
387First Unique Character in a StringPythonO(n)O(1)Easy
388Longest Absolute File PathPythonMedium
389Find the DifferencePythonO(n)O(1)Easy
409Longest PalindromePythonEasy
424Longest Repeating Character ReplacementPythonMedium
438Find All Anagrams in a StringPythonEasy
447Number of BoomerangsPythonO(n^2)O(n)Easy
4544Sum IIPython$O(n^2)$O(n)Medium
470Implement Rand10() Using Rand7()PythonMedium
473Matchsticks to SquarePythonMedium
500Keyboard RowPythonO(n)O(n)Easy
523Continuous Subarray SumPythonMedium
532K-diff Pairs in an ArrayPythonEasy
554Brick WallPythonMedium
560Subarray Sum Equals KPythonMedium
561Array Partition IPython$O(nlog_2(n))$O(1)Easy
575Distribute CandiesPythonEasy
594Longest Harmonious SubsequencePythonEasy
599Minimum Index Sum of Two ListsPythonEasy
609Find Duplicate File in SystemPythonMedium
721Accounts MergePythonMedium
734Sentence SimilarityPythonEasy
737Sentence Similarity IIPythonMedium
748Shortest Completing WordPythonEasy
760Find Anagram MappingsPythonEasy
771Jewels and StonesPythonO(n)O(1)Easy
811Subdomain Visit CountPythonEasy
822Card Flipping GamePythonMedium
825Friends Of Appropriate AgesPythonMedium
869Reordered Power of 2PythonMedium
873Length of Longest Fibonacci SubsequencePythonMedium

Math

#TitleSolutionTimeSpaceDifficulty
007Reverse IntegerPythonO(n)O(1)Easy
009Palindrome NumberPythonO(1)O(1)Easy
012Integer to RomanPythonMedium
013Roman to IntegerPythonO(n)O(1)Easy
026Remove Duplicates from Sorted ArrayPython$O(n)$O(1)Easy
029Divide Two IntegersPythonMedium
050Pow(x, n)PythonMedium
060Permutation SequencePythonMedium
065Valid NumberPythonHard
066Plus OnePythonO(n)O(n)Easy
067Add BinaryPythonEasy
089Gray CodePythonMedium
166Fraction to Recurring DecimalPythonMedium
168Excel Sheet Column TitlePythonEasy
171Excel Sheet Column NumberPythonO(n)O(1)Easy
172Factorial Trailing ZeroesPythonO(1)O(1)Easy
202Happy NumberPythonO(n)O(1)Easy
204Count PrimesPythonO(n)O(n)Easy
223Rectangle AreaPythonEasy
231Power of TwoPythonO(1)O(1)Easy
233Number of Digit OnePythonHard
248Strobogrammatic Number IIIPythonHard
258Add DigitsPythonO(n)O(1)Easy
263Ugly NumberPythonEasy
268Missing NumberPythonO(n)O(1)Medium
292Nim GamePythonO(1)O(1)Easy
319Bulb SwitcherPythonMedium
326Power of ThreePythonO(1)O(1)Easy
335Self CrossingPythonHard
343Integer BreakPythonMedium
365Water and Jug ProblemPythonMedium
367Valid Perfect SquarePythonO(1)O(1)Easy
372Super PowPythonMedium
382Linked List Random NodePythonMedium
386Lexicographical NumbersPythonMedium
390Elimination GamePythonMedium
391Perfect RectanglePythonHard
398Random Pick IndexPythonMedium
400Nth DigitPythonEasy
413Arithmetic SlicesPythonMedium
423Reconstruct Original Digits from EnglishPythonMedium
441Arranging CoinsPythonEasy
453Minimum Moves to Equal Array ElementsPythonEasy
458Poor PigsPythonEasy
469Convex PolygonPythonMedium
470Implement Rand10() Using Rand7()PythonMedium
517Super Washing MachinesPythonHard
537Complex Number MultiplicationPythonMedium
553Optimal DivisionPythonMedium
573Squirrel SimulationPythonMedium
593Valid SquarePythonMedium
592Fraction Addition and SubtractionPythonMedium
598Range Addition IIPythonO(n)O(1)Easy
625Minimum FactorizationPythonMedium
628Maximum Product of Three NumbersPythonEasy
633Sum of Square NumbersPythonEasy
634Find the Derangement of An ArrayPythonMedium
640Solve the EquationPythonMedium
6514 Keys KeyboardPythonMedium
660Remove 9PythonHard
672Bulb Switcher IIPythonMedium
728Self Dividing NumbersPythonO(n)O(1)Medium
754Reach a NumberPythonMedium
775Global and Local InversionsPythonMedium
779K-th Symbol in GrammarPythonMedium
780Reaching PointsPythonHard
781Rabbits in ForestPythonMedium
782Transform to ChessboardPythonHard
789Escape The GhostsPythonMedium
800Similar RGB ColorPythonEasy
810Chalkboard XOR GamePythonHard
812Largest Triangle AreaPythonEasy
829Consecutive Numbers SumPythonMedium
836Rectangle OverlapPythonEasy
858Mirror ReflectionPythonMedium
867Prime PalindromePythonMedium
880Random Pick with WeightPythonMedium
881Random Flip MatrixPythonMedium
882Random Point in Non-overlapping RectanglesPythonMedium
883Generate Random Point in a CirclePythonMedium

Sort

#TitleSolutionTimeSpaceDifficulty
056Merge IntervalsPythonO(n)O(1)Medium
057Insert IntervalPythonHard
075Sort ColorsPythonO(n)O(1)Medium
088Merge Sorted ArrayPythonO(n)O(1)Easy
147Insertion Sort ListPythonMedium
148Sort ListPythonMedium
164Maximum GapPythonHard
179Largest NumberPythonO(nlogn)O(1)Medium
218The Skyline ProblemPythonHard
242Valid AnagramPythonO(n)O(1)Easy
252Meeting RoomsPythonEasy
253Meeting Rooms IIPythonMedium
274H-IndexPythonMedium
280Wiggle SortPythonMedium
324Wiggle Sort IIPythonMedium
347Top K Frequent ElementsPythonMedium
406Queue Reconstruction by HeightPythonMedium
451Sort Characters By FrequencyPythonO(nlogn)1Medium
692Top K Frequent WordsPythonMedium

Two Pointers

#TitleSolutionTimeSpaceDifficulty
019Remove Nth Node From End of ListPythonO(n)O(1)Easy
028Implement strStr()PythonO(n)O(1)Easy
035Search Insert PositionPython$O(log_2(n))$O(1)Easy
086Partition ListPythonMedium
125Valid PalindromePythonO(n)O(1)Easy
141Linked List CyclePythonO(n)O(1)Easy
142Linked List Cycle IIPythonMedium
143Reorder ListPythonMedium
167Two Sum II - Input array is sortedPythonO(n)O(n)Easy
2593Sum SmallerPythonMedium
283Move ZeroesPythonO(n)O(1)Easy
287Find the Duplicate NumberPythonHard
344Reverse StringPythonO(n)O(1)Easy
345Reverse Vowels of a StringPythonO(n)O(1)Easy
350Intersection of Two Arrays IIPythonO(n)O(1)Easy
360Sort Transformed ArrayPythonMedium
457Circular Array LoopPythonMedium
567Permutation in StringPythonMedium
611Valid Triangle NumberPythonMedium
777Swap Adjacent in LR StringPythonMedium
826Most Profit Assigning WorkPythonMedium
828Unique Letter StringPythonHard
844Backspace String ComparePythonEasy
876Middle of the Linked ListPythonEasy

Recursion

#TitleSolutionTimeSpaceDifficulty
095Unique Binary Search Trees IIPythonMedium
098Validate Binary Search TreePythonMedium
100Same TreePythonEasy
105Construct Binary Tree from Preorder and Inorder TraversalPythonMedium
106Construct Binary Tree from Inorder and Postorder TraversalPythonMedium
108Convert Sorted Array to Binary Search TreePythonMedium
109Convert Sorted List to Binary Search TreePythonMedium
110Balanced Binary TreePythonO(logn)O(1)Easy
111Minimum Depth of Binary TreePythonEasy
114Flatten Binary Tree to Linked ListPythonMedium
116Populating Next Right Pointers in Each NodePythonMedium
124Binary Tree Maximum Path SumPythonHard
129Sum Root to Leaf NumbersPythonMedium
156Binary Tree Upside DownPythonMedium
241Different Ways to Add ParenthesesPythonMedium
298Binary Tree Longest Consecutive SequencePythonO(n)O(1)Medium
327Count of Range SumPythonHard
333Largest BST SubtreePythonMedium
337House Robber IIIPythonO(logn)O(1)Medium
395Longest Substring with At Least K Repeating CharactersPythonMedium
404Sum of Left LeavesPythonEasy
437Path Sum IIIPythonEasy
544Output Contest MatchesPythonMedium
549Binary Tree Longest Consecutive Sequence IIPythonMedium
669Trim a Binary Search TreePythonEasy
671Second Minimum Node In a Binary TreePythonEasy
761Special Binary StringPythonHard

Binary Search

#TitleSolutionTimeSpaceDifficulty
004Median of Two Sorted ArraysPythonO(log(n))O(1)Hard
033Search in Rotated Sorted ArrayPythonO(logn)O(1)Medium
034Search for a RangePythonMedium
305Search Insert PositionPythonMedium
069Sqrt(x)PythonO(logn)O(1)Easy
074Search a 2D MatrixPythonMedium
081Search in Rotated Sorted Array IIPythonO(logn)~O(n)O(1)Medium
153Find Minimum in Rotated Sorted ArrayPython$O(log_2(n))$O(1)Medium
154Find Minimum in Rotated Sorted Array IIPython$O(log_2(n))-O(n)$O(1)Hard
162Find Peak ElementPython$O(log_2(n))$O(1)Medium
167Two Sum II - Input array is sortedPythonO(n)O(n)Easy
222Count Complete Tree NodesPythonMedium
275H-Index IIPythonMedium
278First Bad VersionPython$O(log_2(n))$O(1)Easy
300Longest Increasing SubsequencePythonO(nlogn)O(1)~O(n)Medium
302Smallest Rectangle Enclosing Black PixelsPythonHard
354Russian Doll EnvelopesPythonHard
363Max Sum of Rectangle No Larger Than KPythonHard
367Valid Perfect SquarePythonO(1)O(1)Easy
374Guess Number Higher or LowerPythonEasy
410Split Array Largest SumPythonHard
436Find Right IntervalPythonMedium
475HeatersPythonEasy
540Single Element in a Sorted ArrayPythonMedium
658Find K Closest ElementsPythonMedium
668Kth Smallest Number in Multiplication TablePythonO(min(m,n)log(m*n))O(1)Hard
704Binary SearchPythonO(nlogn)O(1)Easy
719Find K-th Smallest Pair DistancePythonHard
744Find Smallest Letter Greater Than TargetPython$O(log_2(n))$O(1)Easy
774Minimize Max Distance to Gas StationPythonHard
786K-th Smallest Prime FractionPythonHard
793Preimage Size of Factorial Zeroes FunctionPythonHard
852Peak Index in a Mountain ArrayPythonO($lon_2(n)$)O(1)Easy
864Random Pick with BlacklistPythonHard
875Koko Eating BananasPythonMedium
878Nth Magical NumberPythonHard

Binary Search Tree

#TitleSolutionTimeSpaceDifficulty
220Contains Duplicate IIIPython$O(n^2)$O(1)Medium
230Kth Smallest Element in a BSTPythonO(logn)O(n)Medium
235Lowest Common Ancestor of a Binary Search TreePythonO(n)O(1)Easy
270Closest Binary Search Tree ValuePythonEasy
285Inorder Successor in BSTPythonMedium
352Data Stream as Disjoint IntervalsPythonHard
449Serialize and Deserialize BSTPythonMedium
450Delete Node in a BSTPythonMedium
530Minimum Absolute Difference in BSTPythonEasy
776Split BSTPythonMedium
783Minimum Distance Between BST NodesPythonEasy

Breadth-First Search

#TitleSolutionTimeSpaceDifficulty
102Binary Tree Level Order TraversalPythonO(n)O(n)Medium
107Binary Tree Level Order Traversal IIPythonEasy
103Binary Tree Zigzag Level Order TraversalPythonMedium
117Populating Next Right Pointers in Each Node IIPythonHard
127Word LadderPythonMedium
130Surrounded RegionsPythonMedium
133Clone GraphPythonMedium
207Course SchedulePython+ \
210Course Schedule IIPython+ \
261Graph Valid TreePython+ \
269Alien DictionaryPythonHard
286Walls and GatesPythonMedium
310Minimum Height TreesPythonMedium
317Shortest Distance from All BuildingsPythonHard
433Minimum Genetic MutationPythonMedium
444Sequence ReconstructionPythonMedium
54201 MatrixPythonMedium
666Path Sum IVPythonMedium
675Cut Off Trees for Golf EventPythonHard
742Closest Leaf in a Binary TreePythonMedium
743Network Delay TimePython* log\
752Open the LockPythonMedium
773Sliding PuzzlePythonHard
787Cheapest Flights Within K StopsPython* log\
815Bus RoutesPython+ \
854K-Similar StringsPythonHard
865Shortest Path to Get All KeysPythonHard

Depth-First Search

#TitleSolutionTimeSpaceDifficulty
104Maximum Depth of Binary TreePythonO(n)O(1)Easy
112Path SumPythonO(n)O(1)Easy
113Path Sum IIPythonMedium
199Binary Tree Right Side ViewPythonMedium
200Number of IslandsPythonMedium
236Lowest Common Ancestor of a Binary TreePythonMedium
247Strobogrammatic Number IIPythonMedium
250Count Univalue SubtreesPythonMedium
257Binary Tree PathsPythonEasy
282Expression Add OperatorsPythonHard
301Remove Invalid ParenthesesPythonHard
329Longest Increasing Path in a MatrixPythonHard
332Reconstruct ItineraryPythonMedium
339Nested List Weight SumPythonEasy
364Nested List Weight Sum IIPythonMedium
366Find Leaves of Binary TreePythonMedium
399Evaluate DivisionPython!)_
417Pacific Atlantic Water FlowPythonMedium
440K-th Smallest in Lexicographical OrderPythonHard
464Can I WinPythonMedium
515Find Largest Value in Each Tree RowPythonMedium
547Friend CirclesPythonMedium
582Kill ProcessPythonMedium
638Shopping OffersPythonMedium
690Employee ImportancePythonEasy
694Number of Distinct IslandsPythonMedium
695Max Area of IslandPythonEasy
711Number of Distinct Islands IIPythonHard
733Max Area of IslandPythonEasy
749Contain VirusPythonHard
753Cracking the SafePythonHard
756Pyramid Transition MatrixPythonMedium
785Is Graph Bipartite?Python+ \
797All Paths From Source to TargetPythonMedium
802Find Eventual Safe StatesPython+ \
827Making A Large IslandPythonHard
834Sum of Distances in TreePythonHard
841Keys and RoomsPythonMedium
851Loud and RichPythonMedium

Backtracking

#TitleSolutionTimeSpaceDifficulty
017Letter Combinations of a Phone NumberPythonMedium
022Generate ParenthesesPythonMedium
037Sudoku SolverPythonHard
039Combination SumPythonMedium
040Combination Sum IIPythonMedium
046PermutationsPythonMedium
047Permutations IIPythonMedium
051N-QueensPythonHard
052N-Queens-IIPythonHard
077CombinationsPythonMedium
078SubsetsPythonO(n2)O(1)Medium
079Word SearchPythonMedium
090Subsets IIPythonO(n^2)O(1)Medium
093Restore IP AddressesPythonMedium
126Word Ladder IIPythonHard
131Palindrome PartitioningPythonMedium
140Word Break IIPythonHard
212Word Search IIPythonHard
216Combination Sum IIIPythonMedium
254Factor CombinationsPythonMedium
267Palindrome Permutation IIPythonMedium
291Word Pattern IIPythonHard
294Flip Game IIPythonMedium
320Generalized AbbreviationPythonMedium
425Word SquaresPythonHard
526Beautiful ArrangementPythonMedium
676Implement Magic DictionaryPythonMedium
67924 GamePythonHard
698Partition to K Equal Sum SubsetsPythonMedium
718Maximum Length of Repeated SubarrayPythonMedium
784Letter Case PermutationPythonEasy

Dynamic Programming

#TitleSolutionTimeSpaceDifficulty
010Regular Expression MatchingPythonHard
053Maximum SubarrayPythonO(n)O(1)Easy
062Unique PathsPythonO(n*m)O(n)Medium
063Unique Paths IIPythonMedium
064Minimum Path SumPythonO(n^2)O(1)Medium
070Climbing StairsPythonO(n)O(1)Easy
072Edit DistancePythonO(m*n)O(m)/O(n)Hard
087Scramble StringPythonHard
091Decode WaysPythonO(n)O(1)Medium
096Unique Binary Search TreesPythonO(n^2)O(n)Medium
097Interleaving StringPythonHard
115Distinct SubsequencesPythonHard
120TrianglePythonO(n^2)O(1)Medium
123Best Time to Buy and Sell Stock IIIPythonHard
121Best Time to Buy and Sell StockPythonO(n)O(1)Easy
132Palindrome Partitioning IIPythonHard
139Word BreakPythonMedium
152Maximum Product SubarrayPythonMedium
174Dungeon GamePythonHard
188Best Time to Buy and Sell Stock IVPythonHard
198House RobberPythonO(n)O(1)Easy
213House Robber IIPythonO(n)O(1)Medium
221Maximal SquarePythonMedium
256Paint HousePythonMedium
265Paint House IIPythonHard
276Paint FencePythonEasy
279Perfect SquaresPythonO(log_2n)O(1)Medium
303Range Sum Query - ImmutablePythonEasy
304Range Sum Query 2D - ImmutablePythonMedium
309Best Time to Buy and Sell Stock with CooldownPythonMedium
312Burst BalloonsPythonHard
322Coin ChangePythonMedium
338Counting BitsPythonO(n)O(n)Medium
351Android Unlock PatternsPythonMedium
357Count Numbers with Unique DigitsPythonMedium
361Bomb EnemyPythonMedium
368Largest Divisible SubsetPythonMedium
375Guess Number Higher or Lower IIPythonMedium
377Combination Sum IVPythonMedium
416Partition Equal Subset SumPythonMedium
403Frog JumpPythonHard
418Sentence Screen FittingPythonMedium
446Arithmetic Slices II - SubsequencePythonHard
465Optimal Account BalancingPythonHard
466Count The RepetitionsPythonHard
467Unique Substrings in Wraparound StringPythonMedium
471Encode String with Shortest LengthPythonMedium
472Concatenated WordsPythonMedium
474Ones and ZeroesPythonMedium
486Predict the WinnerPythonMedium
514Freedom TrailPythonHard
516Longest Palindromic SubsequencePythonMedium
546Remove BoxesPythonHard
552Student Attendance Record IIPythonHard
562Longest Line of Consecutive One in MatrixPythonMedium
568Maximum Vacation DaysPythonHard
576Out of Boundary PathsPythonMedium
583Delete Operation for Two StringsPythonMedium
600Non-negative Integers without Consecutive OnesPythonHard
629K Inverse Pairs ArrayPythonHard
639Decode Ways IIPythonHard
6502 Keys KeyboardPythonMedium
656Coin PathPythonHard
664Strange PrinterPythonHard
673Number of Longest Increasing SubsequencePythonMedium
688Knight Probability in ChessboardPythonMedium
689Maximum Sum of 3 Non-Overlapping SubarraysPythonHard
691Stickers to Spell WordPythonHard
712Minimum ASCII Delete Sum for Two StringsPythonMedium
714Best Time to Buy and Sell Stock with Transaction FeePythonMedium
727Minimum Window SubsequencePythonHard
730Count Different Palindromic SubsequencesPythonHard
740Delete and EarnPythonMedium
741Cherry PickupPythonHard
746Min Cost Climbing StairsPythonEasy
764Largest Plus SignPythonMedium
750Number Of Corner RectanglesPythonMedium
788Rotated DigitsPythonO(n)O(1)Easy
790Domino and Tromino TilingPythonMedium
799Champagne TowerPythonMedium
801Minimum Swaps To Make Sequences IncreasingPythonMedium
805Split Array With Same AveragePythonHard
808Soup ServingsPythonMedium
813Largest Sum of AveragesPythonMedium
818Race CarPythonHard
823Binary Trees With FactorsPythonMedium
837New 21 GamePythonMedium
838Push DominoesPythonMedium
847Shortest Path Visiting All NodesPythonHard
877Stone GamePythonO(n)O(1)Medium
879Profitable SchemesPython

Greedy

#TitleSolutionTimeSpaceDifficulty
011Container With Most WaterPythonO(n)O(1)Medium
042Trapping Rain WaterPythonHard
044Wildcard MatchingPythonHard
045Jump Game IIPythonHard
055Jump GamePythonMedium
122Best Time to Buy and Sell Stock IIPythonO(n)O(1)Easy
134Gas StationPythonMedium
135CandyPythonHard
316Remove Duplicate LettersPythonHard
321Create Maximum NumberPythonHard
330Patching ArrayPythonHard
376Wiggle SubsequencePythonMedium
392Is SubsequencePythonMedium
397Integer ReplacementPythonMedium
402Remove K DigitsPythonMedium
435Non-overlapping IntervalsPythonMedium
452Minimum Number of Arrows to Burst BalloonsPythonMedium
455Assign CookiesPythonEasy
621Task SchedulerPythonMedium
630Course Schedule IIIPythonHard
646Maximum Length of Pair ChainPythonMedium
649Dota2 SenatePythonMedium
659Split Array into Consecutive SubsequencesPythonMedium
738Monotone Increasing DigitsPythonMedium
757Set Intersection Size At Least TwoPythonHard
759Employee Free TimePythonHard
763Partition LabelsPythonMedium
767Reorganize StringPythonMedium
798Smallest Rotation with Highest ScorePythonHard
843Guess the WordPythonHard
861Score After Flipping MatrixPythonMedium
870Advantage ShufflePythonMedium

Graph

#TitleSolutionTimeSpaceDifficulty
765Couples Holding HandsPythonHard

Geometry

#TitleSolutionTimeSpaceDifficulty
587Erect the FencePythonHard

Simulation

#TitleSolutionTimeSpaceDifficulty
874Walking Robot SimulationPythonEasy

Design

#TitleSolutionTimeSpaceDifficulty
146LRU CachePythonHard
155Min StackPython--------Easy
225Implement Stack using QueuesPython__Easy
284Peeking IteratorPythonMedium
348Design Tic-Tac-ToePythonMedium
353Design Snake GamePythonMedium
355Design TwitterPythonMedium
359Logger Rate LimiterPythonEasy
362Design Hit CounterPythonMedium
379Design Phone DirectoryPythonMedium
380Insert Delete GetRandom O(1)PythonHard
381Insert Delete GetRandom O(1) - Duplicates allowedPythonHard
384Shuffle an ArrayPythonO(n)O(1)Medium
432All O`one Data StructurePythonHard
460LFU CachePythonHard
535Encode and Decode TinyURLPythonMedium
588Design In-Memory File SystemPythonHard
604Design Compressed String IteratorPythonEasy
622Design Circular QueuePythonMedium
631Design Excel Sum FormulaPythonHard
635Design Log Storage SystemPythonMedium
642Design Search Autocomplete SystemPythonHard
707Design Linked ListPython--Easy
715Range ModulePythonHard
716Max StackPythonEasy
745Prefix and Suffix SearchPythonHard

Divide and Conquer

#TitleSolutionTimeSpaceDifficulty
169Majority ElementPython$O(nlog_2(n))$O(1)Easy

SQL

#TitleSolutionDifficulty
175Combine Two TablesMySQLEasy
176Second Highest SalaryMySQLEasy
177Nth Highest SalaryMySQLMedium
178Rank ScoresMySQLMedium
180Consecutive NumbersMySQLMedium
181Employees Earning More Than Their ManagersMySQLEasy
182Duplicate EmailsMySQLEasy
183Customers Who Never OrderMySQLEasy
184Department Highest SalaryMySQLMedium
185Department Top Three SalariesMySQLHard
196Delete Duplicate EmailsMySQLEasy
197Rising TemperatureMySQLEasy
262Trips and UsersMySQLHard
595Big CountriesMySQLEasy
620Not Boring MoviesMySQLEasy
627Swap SalaryMySQLEasy

Shell Script

#TitleSolutionDifficulty
192Word FrequencyShellMedium
193Valid Phone NumbersShellEasy
194Transpose FileShellMedium
195Tenth LineShellEasy

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

20 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages