Skip to content

This repository contains the solutions and explanations to the algorithm problems on LeetCode. Only medium or above are included. All are written in C++/Python and implemented by myself. The problems attempted multiple times are labelled with hyperlinks.

Notifications You must be signed in to change notification settings

riooooorio/LeetCode

 
 

Repository files navigation

My LeetCode Daily Problem & Contest Group: See rules and score board here

(If you are interested in joining this group, ping me guan.huifeng@gmail.com)

LeetCode难题代码和算法要点分析

目前分类目录:

003.Longest Substring Without Repeating Character (E+)
011.Container-With-Most-Water (M+)
015.3Sum (M)
016.3Sum-Closet (M)
018.4Sum (M)
259.3Sum-Smaller (M+)
030.Substring-with-Concatenation-of-All-Words (H)
075.Sort-Colors (M+)
076.Minimum Window Substring (M+)
026.Remove Duplicates from Sorted Array (H-)
080.Remove Duplicates from Sorted Array II (H)
209.Minimum-Size-Subarray-Sum (M)
088.Merge Sorted Array (M)
283.Move-Zeroes (M)
141.Linked-List-Cycle (E+)
142.Linked-List-Cycle-II (M+)
287.Find-the-Duplicate-Number (H)
340.Longest-Substring-with-At-Most-K-Distinct-Characters (H)
532.K-diff-Pairs-in-an-Array (H-)
360.Sort-Transformed-Array (M)
159.Longest-Substring-with-At-Most-Two-Distinct-Characters(H-)
611.Valid-Triangle-Number (M+)
713.Subarray-Product-Less-Than-K (M+)
992.Subarrays-with-K-Different-Integers (H-)
1052.Grumpy-Bookstore-Owner (M+)
1234.Replace-the-Substring-for-Balanced-String (H-)

004.Median-of-Two-Sorted-Arrays (H)
154.Find-Minimum-in-Rotated-Sorted-Array-II (H-)    
033.Search-in-Rotated-Sorted-Array (M)
081.Search-in-Rotated-Sorted-Array-II (M)
034.Search-for-a-Range (M)
162.Find-Peak-Element (H-)
275.H-index II (H)
302.Smallest-Rectangle-Enclosing-Black-Pixels (M+)
410.Split-Array-Largest-Sum (H)
475.Heaters (H-)
483.Smallest-Good-Base (H)
029.Divide-Two-Integers (M+)
644.Maximum-Average-Subarray-II (H)
719.Find-K-th-Smallest-Pair-Distance (H-)
774.Minimize-Max-Distance-to-Gas-Station (H)
786.K-th-Smallest-Prime-Fraction (M+)
1102.Path-With-Maximum-Minimum-Value (H-)
1157.Online-Majority-Element-In-Subarray (H-)
1201.Ugly-Number-III (TBD)
1231.Divide-Chocolate (TBD)

049.Group-Anagrams (M+)
149.Max-Points-on-a-Line (H)
166.Fraction-to-Recurring-Decimal (M)
170.Two-Sum-III-Data-structure-design (M)
392.Is-Subsequence (H-)
204.Count Primes (M)
274.H-Index (H)
325.Maximum-Size-Subarray-Sum-Equals-k (M)
409.Longest-Palindrome (M)
447.Number-of-Boomerangs (E+)
438.Find-All-Anagrams-in-a-String (M+)
525.Contiguous-Array (M)
356.Line-Reflection (H-)
594.Longest-Harmonious-Subsequence (M+)
532.K-diff-Pairs-in-an-Array (E+)
424.Longest-Repeating-Character-Replacement (H)
446.Arithmetic-Slices-II-Subsequence (H)
128.Longest-Consecutive-Sequence (H-)
753.Cracking-the-Safe (H)
930.Binary-Subarrays-With-Sum (H)
939.Minimum-Area-Rectangle (M+)
982.Triples-with-Bitwise-AND-Equal-To-Zero (M+) (TBD)
1224.Maximum-Equal-Frequency (H-) (TBD)

295.Find-Median-from-Data-Stream (M)
363.Max-Sum-of-Rectangle-No-Larger-Than-K (H)
352.Data-Stream-as-Disjoint-Intervals (H)
480.Sliding-Window-Median (H)
218.The-Skyline-Problem (H)
699.Falling-Squares (H)
715.Range-Module (H)
729.My-Calendar-I (M)
975.Odd-Even-Jump (H-)

270.Closest-Binary-Search-Tree-Value (M+)
095.Unique-Binary-Search-Trees-II (H)
094.Binary Tree Inorder Traversal (H-)
144.Binary-Tree-Preorder-Traversal (M+)
145.Binary-Tree-Postorder-Traversal (H-)
110.Balanced-Binary-Tree (M+)
124.Binary-Tree-Maximum-Path-Sum (M+)
236.Lowest-Common-Ancestor-of-a-Binary-Tree (H)
297.Serialize-and-Deserialize-Binary-Tree (H-)
105.Construct-Binary-Tree-from-Preorder-and-Inorder-Traversal (H-)
106.Construct-Binary-Tree-from-Inorder-and-Postorder-Traversal (M+)
099.Recover-Binary-Search-Tree (H)
114.Flatten-Binary-Tree-to-Linked-List (M+)
098.Validate-Binary-Search-Tree (M)
117.Populating Next Right Pointers in Each Node II (H)
156.Binary-Tree-Upside-Down (H)
285.Inorder-Successor-in-BST (M)
298.Binary-Tree-Longest-Consecutive Sequence (M+)
450.Delete-Node-in-a-BST (H)
437.Path-Sum-III (H-)
255.Verify-Preorder-Sequence-in-Binary-Search-Tree (H)
449.Serialize-and-Deserialize-BST (H)
333.Largest-BST-Subtree (H)
543.Diameter-of-Binary-Tree (M+)
572.Subtree-of-Another-Tree (M)
549.Binary-Tree-Longest-Consecutive-Sequence-II (M)
173.Binary-Search-Tree-Iterator (M)
545.Boundary-of-Binary-Tree (H-)
272.Closest-Binary-Search-Tree-Value-II (M+)
310.Minimum-Height-Trees (H-)
331.Verify-Preorder-Serialization-of-a-Binary-Tree (H)
226.Invert-Binary-Tree (M)
655.Print-Binary-Tree (M+)
501.Find-Mode-in-Binary-Search-Tree (M+)
558.Quad-Tree-Intersection (M+)
662.Maximum-Width-of-Binary-Tree (H-)
652.Find-Duplicate-Subtrees (M)
687.Longest-Univalue-Path (M+)
742.Closest-Leaf-in-a-Binary-Tree (H)
834.Sum-of-Distances-in-Tree (H)
863.All-Nodes-Distance-K-in-Binary-Tree (H-)
954.Check-Completeness-of-a-Binary-Tree (M+)

307.Range-Sum-Query-Mutable (M)
370.Range-Addition (M+)
218.The-Skyline-Problem (H)
699.Falling-Squares (H)
715.Range-Module (H)
1157.Online-Majority-Element-In-Subarray (H)

[Binary_Index_Tree]

307.Range-Sum-Query-Mutable (M)

146.LRU-Cache (H-)
460.LFU Cache (H)
432.All-O-one-Data-Structure (H)
380.Insert-Delete-GetRandom-O(1) (M+)
381.Insert-Delete-GetRandom-O-1-Duplicates-allowed (H-)
716.Max-Stack (M+)
355.Design-Twitter (H)
535.Encode-and-Decode-TinyURL (M)
631.Design-Excel-Sum-Formula (H)
642.Design-Search-Autocomplete-System (M+)
895.Maximum-Frequency-Stack (H)
1172.Dinner-Plate-Stacks (TBD)

032.Longest-Valid-Parentheses (H)
155.Min-Stack (M)
225.Implement Stack using Queues (H-)
232.Implement-Queue-using-Stacks (H-)
255.Verify-Preorder-Sequence-in-Binary-Search-Tree (H)
341.Flatten-Nested-List-Iterator (M)
173.Binary-Search-Tree-Iterator (M)
536.Construct-Binary-Tree-from-String (M)
456.132-Pattern (H-)
084.Largest-Rectangle-in-Histogram (H)
085.Maximal-Rectangle (H-)
402.Remove-K-Digits (H-)
316.Remove-Duplicate-Letters (H)
496.Next-Greater-Element-I (H-)
503.Next-Greater-Element-II (H-)
221.Maximal-Square (H-)
636.Exclusive-Time-of-Functions (H-)
739.Daily-Temperatures (H-)
901.Online-Stock-Span (H-)
907.Sum-of-Subarray-Minimums (H)
946.Validate-Stack-Sequences(H-)
962.Maximum-Width-Ramp (H)
1124.Longest-Well-Performing-Interval (H)
1130.Minimum-Cost-Tree-From-Leaf-Values (H)

004.Median-of-Two-Sorted-Arrays (H)
239.Sliding-Window-Maximum (H)
358.Rearrange-String-k-Distance-Apart (H-)
378.Kth-Smallest-Element-in-a-Sorted-Matrix (H-)
373.Find-K-Pairs-with-Smallest-Sums (H)
591.Tag-Validator (H)
632.Smallest-Range (M)
642.Design-Search-Autocomplete-System (M+)
621.Task-Scheduler (H-)
774.Minimize-Max-Distance-to-Gas-Station (H)
1066.Campus-Bikes-II (H)

037.Sudoku-Solver (H-)
051.N-Queens (H)
417.Pacific-Atlantic-Water-Flow (M)
200.Number-of-Islands (M)
282.Expression-Add-Operators (H)
312.Burst-Balloons (H-)
399.Evaluate-Division (H-)
488.Zuma-Game (H-)
332.Reconstruct-Itinerary (H)
425.Word-Squares (H-)
465.Optimal-Account-Balancing (H)
959.Regions-Cut-By-Slashes (M+)
1192.Critical-Connections-in-a-Network (H)

126.Word-Ladder-II (M+)
130.Surrounded-Regions (H-)
200.Number-of-Islands (H-)
269.Alien-Dictionary (H)
407.Trapping-Rain-Water-II (H-)
778.Swim-in-Rising-Water (H-)
529.Minesweeper (M+)
637.Average-of-Levels-in-Binary-Tree (M)
675.Cut-Off-Trees-for-Golf-Event (M)
694.Number-of-Distinct-Islands (M+)
743.Network-Delay-Time (H)
785.Is-Graph-Bipartite (M+)
815.Bus-Routes (M+)
847.Shortest-Path-Visiting-All-Nodes (H-)
864.Shortest-Path-to-Get-All-Keys (H-)
928.Minimize-Malware-Spread-II (H-)
913.Cat-and-Mouse (H+)
1036.Escape-a-Large-Maze (H)

208.Implement-Trie--Prefix-Tree (M+)
211.Add-and-Search-Word (H-)
421.Maximum XOR of Two Numbers in an Array (H)
648.Replace-Words (H)
588.Design-In-Memory-File-System (H-)
677.Map-Sum-Pairs (M)
676.Implement-Magic-Dictionary (H-)
212.Word-Search-II (H-)
745.Prefix-and-Suffix-Search (H-)

084.Largest-Rectangle-in-Histogram (H)
085.Maximal-Rectangle (H)
134.Gas-Station (H)
221.Maximal-Square (H)
239.Sliding-Window-Maximum (H)
300.Longest-Increasing-Subsequence (M+)
334.Increasing-Triplet-Subsequence (H-)
354.Russian-Doll-Envelopes
316.Remove Duplicate Letters (H)
358.Rearrange-String-k-Distance-Apart
045.Jump-Game-II (H)
229.Majority-Element-II (H)
659.Split-Array-into-Consecutive-Subsequences (H-)
484.Find-Permutation (H)
386.Lexicographical-Numbers (H)
440.K-th-Smallest-in-Lexicographical-Order (H)
621.Task-Scheduler (H-)
624.Maximum-Distance-in-Arrays (M)
665.Non-decreasing-Array (H-)
670.Maximum-Swap (M+)
678.Valid-Parenthesis-String (H)
321.Create-Maximum-Number (H)
135.Candy (M+)
649.Dota2-Senate (H)
330.Patching-Array (H)
650.2-Keys-Keyboard (M+)
683.K-Empty-Slots (H)
517.Super-Washing-Machines (H)
757.Set-Intersection-Size-At-Least-Two (H)
739.Daily-Temperatures (M+)
826.Most-Profit-Assigning-Work (M)
857.Minimum-Cost-to-Hire-K-Workers (H)
862.Shortest-Subarray-with-Sum-at-Least-K (H)
871.Minimum-Number-of-Refueling-Stops (H-)
910.Smallest-Range-II (M+)
936.Stamping-The-Sequence (H)
948.Bag-of-Tokens (H-)
968.Binary-Tree-Cameras (H)
995.Minimum-Number-of-K-Consecutive-Bit-Flips (H-)
1040.Moving-Stones-Until-Consecutive-II (H)
1054.Distant-Barcodes (M+)
1121.Divide Array Into Increasing Sequences (TBD)

061.Rotate-List
086.Partition-List (M)
142.Linked List Cycle II (M+)
109.Convert-Sorted-List-to-Binary-Search-Tree (M)
092.Reverse-Linked-List-II (H)
143.Reorder-List (H-)
457.Circular-Array-Loop (H-)
708.Insert-into-a-Cyclic-Sorted-List (H-)

174.Dungeon-Game (H-)
264.Ugly-Number-II (M+)
265.Paint-House-II (H)
410.Split-Array-Largest-Sum (H)
322.Coin-Change (M)
518.Coin-Change-2 (H-)
091.Decode-Ways (M)
639.Decode-Ways-II (H)
629.K-Inverse-Pairs-Array (H)
634.Find the Derangement-of-An-Array (H)
650.2-Keys-Keyboard (M+)
221.Maximal-Square (H-)
576.Out-of-Boundary-Paths (H)
600.Non-negative-Integers-without-Consecutive-Ones (H)
656.Coin-Path (H-)
152.Maximum-Product-Subarray (M+)
368.Largest-Divisible-Subset (M+)
446.Arithmetic-Slices-II-Subsequence (H-)
474.Ones-and-Zeroes (H-)
664.Strange-Printer (H)
651.4-Keys-Keyboard (M+)
673.Number-of-Longest-Increasing-Subsequence (M+)
494.Target-Sum (M+)
801.Minimum-Swaps-To-Make-Sequences-Increasing (TBD)
813.Largest-Sum-of-Averages (H)
818.Race-Car (H)
377.Combination-Sum-IV (M)
132.Palindrome-Partitioning-II (H-)
139.Word-Break (M+)
741.Cherry-Pickup (H-)
837.New-21-Game (H-)
787.Cheapest-Flights-Within-K-Stops (H-)
879.Profitable-Schemes (M+)
887.Super-Egg-Drop (H)
903.Valid-Permutations-for-DI-Sequence (H)
920.Number-of-Music-Playlists (H)
935.Knight-Dialer (M)
940.Distinct-Subsequences-II (H)
983.Minimum-Cost-For-Tickets (H-)
1000.Minimum-Cost-to-Merge-Stones (H)
1027.Longest-Arithmetic-Sequence (M+)
1043.Partition-Array-for-Maximum-Sum(M+)
1049.Last-Stone-Weight-II (H-)
1105.Filling-Bookcase-Shelves (H-)
514. Freedom Trail (TBD)

136.Single-Number (M)
260.Single-Number-III (H)
371.Sum-of-Two-Integers (H)
318.Maximum-Product-of-Word-Lengths (M+)
342.Power-of-Four (H)

315.Count-of-Smaller-Numbers-After-Self (H-)
327.Count-of-Range-Sum (H-)
493.Reverse-Pairs (M+)

005.Longest-Palindromic-Substring (H)
006.ZigZag-Conversion (M+)
336.Palindrome-Pairs (H-)
388.Longest-Absolute-File-Path (M+)
408.Valid-Word-Abbreviation (M)
411.Minimum-Unique-Word-Abbreviation (H)
418.Sentence-Screen-Fitting (M+)
527.Word-Abbreviation (M+)
647.Palindromic-Substrings (M+)
556.Next Greater Element III (H-)
028.Implement-strStr (H)
616.Add-Bold-Tag-in-String (M)
467.Unique-Substrings-in-Wraparound-String (H-)
564.Find-the-Closest-Palindrome (H)
722.Remove-Comments (H)
736.Parse-Lisp-Expression (H-)
844.Backspace-String-Compare (M+)

041.First-Missing-Positive (H)
164.Maximum-Gap (H)
581.shortest-unsorted-continuous-subarray (M+)
215.Kth-Largest-Element-in-an-Array (M)
275.H-Index-II (M+)
406.Queue-Reconstruction-by-Height (M+)
442.Find-All-Duplicates-in-an-Array (M+)
448.Find-All-Numbers-Disappeared-in-an-Array (M+)
731.My-Calendar-II (M+)
452.Minimum-Number-of-Arrows-to-Burst-Balloons (H-)
435.Non-overlapping-Intervals (M+)
1024.Video-Stitching (M+)
1235.Maximum-Profit-in-Job-Scheduling (H-)

[Sweep Line]

252.Meeting-Rooms (M)
253.Meeting-Rooms-II (M+)
056.Merge-Intervals (M)
057.Insert-Intervals (M)
732.My-Calendar-III (M)
759.Employee-Free-Time (M+)

547.Friend-Circles (M)
200.Number-of-Islands (H-)
305.Number-of-Islands-II (H)
130.Surrounded-Regions (H-)
128.Longest-Consecutive-Sequence (H-)
684.Redundant-Connection (M)
685.Redundant-Connection-II (H)
721.Accounts-Merge (M+)
765.Couples-Holding-Hands (H-)
785.Is-Graph-Bipartite (M+)
924.Minimize-Malware-Spread (H-)
947.Most-Stones-Removed-with-Same-Row-or-Column (M+)
952.Largest-Component-Size-by-Common-Factor (H)
1101.The-Earliest-Moment-When-Everyone-Become-Friends (M+)
1202.Smallest-String-With-Swaps (M+)

133.Clone-Graph (M+)
241.Different-Ways-to-Add-Parentheses (H-)
390.Elimination-Game (H)
395.Longest-Substring-with-At-Least-K-Repeating-Characters (H)
397.Integer-Replacement (M+)
679.24-Game (H)
761.Special-Binary-String (H)
779.K-th-Symbol-in-Grammar (M)
808.Soup-Servings (H)
877.Stone-Game (M+)
880.Decoded-String-at-Index (H-)
932.Beautiful-Array (H-)
964.Least-Operators-to-Express-Number (H)

  • Min-Max Strategy
    1140.Stone-Game-II

007.Reverse-Integer (M)
042.Trapping-Rain-Water (M+)
048.Rotate-Image (M+)
158.Read-N-Characters-Given-Read4-II-Call-multiple-times (H)
240.Search-a-2D-Matrix-II (M+)
311.Sparse-Matrix-Multiplication (M)
324.Wiggle-Sort-II (M)
593.Valid-Square (H)
168.Excel-Sheet-Column-Title (H)
453.Minimum-Moves-to-Equal-Array-Elements (M)
046.Permutations (M+)
047.Permutations-II (H)
060.Permutation-Sequence (H)
077.Combinations (H-)
587.Erect-the-Fence (H)
087.Scramble-String (H)
391.Perfect-Rectangle (H)
645.Set-Mismatch (H)
423.Reconstruct-Original-Digits-from-English (H-)
335.Self-Crossing (H)
479.Largest-Palindrome-Product (M+)
689.Maximum-Sum-of-3-Non-Overlapping-Subarrays (M+)
782.Transform-to-Chessboard (H+)
466.Count-The-Repetitions (H)
810.Chalkboard-XOR-Game (H)
420.Strong-Password-Checker (H)
214.Shortest-Palindrome (H)
850.Rectangle-Area-II (H-)
794.Valid-Tic-Tac-Toe-State (M+)
798.Smallest-Rotation-with-Highest-Score (H)
825.Friends-Of-Appropriate-Ages (M+)
835.Image-Overlap (H)
855.Exam-Room (M+)
918.Maximum-Sum-Circular-Subarray (H-)
1067.Digit-Count-in-Range (H)
1109.Corporate-Flight-Bookings (M)
1183.Maximum-Number-of-Ones (H)

296.Best-Meeting-Point (M+)
343.Integer-Break (M)
458.Poor-Pigs (H)
672.Bulb-Switcher-II (H)
754.Reach-a-Number (H)
829.Consecutive-Numbers-Sum (M)
963.Minimum-Area-Rectangle-II (H-)
1012.Numbers-With-Repeated-Digits (H-)
1131.Maximum-of-Absolute-Value-Expression (H-)
1191.K-Concatenation-Maximum-Sum (H-)

[Random Pick Series]

382.Linked-List-Random-Node (H)
470.Implement-Rand10()-Using-Rand7() (M+)
478.Generate-Random-Point-in-a-Circle (M+)
519.Random-Flip-Matrix (H-)
710.Random-Pick-with-Blacklist (M+)

About

This repository contains the solutions and explanations to the algorithm problems on LeetCode. Only medium or above are included. All are written in C++/Python and implemented by myself. The problems attempted multiple times are labelled with hyperlinks.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 94.1%
  • Python 5.9%