Skip to content

My personal LeetCode solutions written in Python 3, including explanations, dynamic programming notes, and clean implementations for interview preparation.

License

Notifications You must be signed in to change notification settings

GioiaZheng/Leetcode-Solutions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

287 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LeetCode Solutions Repository

Curated, well-documented Python 3 solutions for a growing set of LeetCode problems. Every problem folder contains:

  • README.md with a concise explanation and complexity notes.
  • solution.py with a clean, runnable implementation.

Use this repo as a reusable algorithm notebook or a quick refresher before interviews.


Repository structure

  • ####-problem-name/ — individual problems; run python solution.py to execute the reference implementation.
  • 0000-notes/ — reusable study notes and templates grouped by topic.
  • LICENSE — repository license details.

Repository map

flowchart TD
    Repo[LeetCode Solutions Repo]
    Repo --> Problems["####-problem-name/"]
    Repo --> Notes["0000-notes/"]
    Repo --> License["LICENSE"]
    Problems --> ProblemReadme["README.md (approach + complexity)"]
    Problems --> ProblemSolution["solution.py (reference implementation)"]
    Notes --> NotesTopics["Topic folders & guides"]


Loading

Notes library highlights

  • How to think: reading prompts, choosing algorithms, and avoiding common mistakes.
  • Core patterns: arrays, hashing, two pointers, sliding window, binary search, prefix sum, greedy, and dynamic programming.
  • Practice helpers: quick references for frequency counting, bucket techniques, interval scheduling, and more.

Notes index

每篇笔记都有对应的中文版本,文件名以 -zh.md 结尾。


Quick start

  1. Clone: git clone <repo-url>
  2. Navigate to a problem directory, e.g. cd 0001-two-sum.
  3. Run the solution: python solution.py
  4. Read the accompanying README.md for the approach, complexity, and edge cases.

Tip: The folder naming convention is <problem-id>-<kebab-case-title> so you can jump directly to the problem you want to review.


Solution format

Each problem folder follows a consistent template so you can skim or reuse ideas quickly.

  • README.md contains the problem summary, key insight, approach, complexity, and a short takeaway.
  • solution.py is a runnable reference solution with type hints and inline notes for tricky steps.

If you want to add a new problem, start by copying any existing folder and updating the metadata.


Quick checks

There is no centralized test runner yet, but you can sanity-check a solution with:

  • python solution.py (runs the sample input if present)
  • python -m py_compile solution.py (verifies syntax)

Problem catalog

A topic-focused index of all solutions currently in the repository.

ID Problem Topics
0001 Two Sum Array; Hash Table
0002 Add Two Numbers Linked List; Math
0003 Longest Substring Without Repeating Characters Sliding Window; Hash Map
0004 Median of Two Sorted Arrays Binary Search; Divide & Conquer
0005 Longest Palindromic Substring String; Expand Around Center; Dynamic Programming
0006 Zigzag Conversion String; Simulation
0007 Reverse Integer Math; Overflow Handling
0008 String to Integer (atoi) String; Parsing
0009 Palindrome Number Math; Two Pointers
0010 Regular Expression Matching Dynamic Programming; Pattern Matching
0011 Container With Most Water Array; Two Pointers
0012 Integer to Roman Math; Mapping
0013 Roman to Integer Math; Mapping
0026 Remove Duplicates from Sorted Array Array; Two Pointers
0027 Remove Element Array; Two Pointers
0028 Find the Index of the First Occurrence in a String String; Two Pointers
0049 Group Anagrams Hash Table; Sorting
0066 Plus One Array; Simulation
0085 Maximal Rectangle Dynamic Programming; Stack; Monotonic Stack
0121 Best Time to Buy and Sell Stock Array; Greedy
0164 Maximum Gap Bucket Sort; Sorting
0220 Contains Duplicate III Sliding Window; Bucket Sort
0242 Valid Anagram Hash Table; Sorting
0347 Top K Frequent Elements Heap; Hash Table
0451 Sort Characters by Frequency Heap; Hash Table
0679 24 Game Backtracking; DFS; Math
0692 Top K Frequent Words Heap; Sorting
0712 Minimum ASCII Delete Sum for Two Strings Dynamic Programming; String
0756 Pyramid Transition Matrix Graph; DFS
0840 Magic Squares in Grid Array; Enumeration
0865 Smallest Subtree with all the Deepest Nodes Tree; Depth-First Search; Binary Tree; Lowest Common Ancestor
0912 Sort an Array Sorting; Divide & Conquer
0944 Delete Columns to Make Sorted Greedy; String
0955 Delete Columns to Make Sorted II Greedy; String
0960 Delete Columns to Make Sorted III Dynamic Programming; String
0961 N-Repeated Element in Size 2N Array Hash Table; Counting
1161 Maximum Level of a Binary Tree Tree; BFS
1266 Minimum Time Visiting All Points Geometry; Greedy; Math
1339 Maximum Product of Splitted Binary Tree Tree; Depth-First Search; Binary Tree; Math
1351 Count Negative Numbers in a Sorted Matrix Matrix; Binary Search
1390 Four Divisors Math; Number Theory
1411 Number of Ways to Paint N x 3 Grid Dynamic Programming; Combinatorics
1458 Max Dot Product of Two Subsequences Dynamic Programming; Array; Subsequence
1523 Count Odd Numbers in an Interval Range Math
1590 Make Sum Divisible by P Prefix Sum; Hash Map; Modular Arithmetic
1895 Largest Magic Square Prefix Sum; Matrix; Enumeration
1925 Count Square Sum Triples Math; Number Theory
1970 Last Day Where You Can Still Cross Binary Search; BFS/Union Find
1975 Maximum Matrix Sum Greedy; Matrix
2047 Find the Largest Area of Square Inside Two Rectangles Geometry; Brute Force; Enumeration
2054 Two Best Non-Overlapping Events Dynamic Programming; Sorting
2092 Find All People With Secret Graph; Union Find
2110 Number of Smooth Descent Periods of a Stock Sliding Window; Counting
2141 Maximum Running Time of N Computers Binary Search; Greedy
2147 Number of Ways to Divide a Long Corridor Dynamic Programming; Combinatorics
2211 Count Collisions on a Road Simulation; Stack
2273 Find Resultant Array After Removing Anagrams String; Stack
2343 Query Kth Smallest Trimmed Number Sorting; Priority Queue
2402 Meeting Rooms III Priority Queue; Scheduling
2435 Paths in Matrix Whose Sum Is Divisible by K Dynamic Programming; Prefix Sum
2483 Minimum Penalty for a Shop Prefix Sum; Enumeration
2872 Maximum Number of K-Divisible Components Tree; DFS; Greedy; Graph
2943 Maximize Area of Square Hole in Grid Greedy; Geometry; Sorting
2975 Maximum Square Area by Removing Fences From a Field Geometry; Hash Set; Greedy
3074 Apple Redistribution into Boxes Greedy; Sorting
3075 Maximize Happiness of Children Greedy; Sorting
3381 Maximum Subarray Sum With Length Divisible by K Prefix Sum; Hash Map
3432 Count Partitions with Even Sum Difference Prefix Sum; Math
3433 Count Mentions Per User Simulation; Hash Table
3453 Separate Squares I Binary Search; Geometry; Prefix Area
3454 Separate Squares II Sweep Line; Segment Tree; Geometry; Binary Search
3512 Minimum Operations to Make Array Sum Divisible by K Math; Greedy; Modular Arithmetic
3531 Count Covered Buildings Geometry; Prefix Min/Max
3562 Maximum Profit from Trading Stocks with Discounts Tree DP; Knapsack
3573 Best Time to Buy and Sell Stock V Dynamic Programming; State Machine
3577 Count the Number of Computer Unlocking Permutations Sorting; Feasibility Check
3578 Count Partitions With Max-Min Difference at Most K Sliding Window; Dynamic Programming
3583 Count Special Triplets Hash Map; Prefix/Suffix Counting
3606 Coupon Code Validator String; Simulation
3623 Count Number of Trapezoids I Array; Geometry
3625 Count Number of Trapezoids II Array; Geometry
3652 Best Time to Buy and Sell Stock using Strategy Prefix Sum; Sliding Window

Contributing

  • Follow the existing folder naming pattern (####-title-in-kebab-case).
  • Provide both README.md (approach & complexity) and solution.py (idiomatic Python).
  • Keep explanations concise and prefer standard library solutions unless an external dependency is necessary.

Happy coding and studying! 🚀

About

My personal LeetCode solutions written in Python 3, including explanations, dynamic programming notes, and clean implementations for interview preparation.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages