Skip to content

About

Python solutions for selected LeetCode problems.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

LeetCode Practice in Python

A focused collection of Python solutions for selected LeetCode problems. Each implementation keeps the core algorithm visible and includes a small runnable example for quick verification.

Problem Index

# Problem Approach Time Space Solution
1 Two Sum Brute force O(n²) O(1) double loop
1 Two Sum Hash table O(n) O(n) hash table
3 Longest Substring Without Repeating Characters Sliding window O(n) O(n) sliding window
11 Container With Most Water Two pointers O(n) O(1) two pointers
15 3Sum Sorting + two pointers O(n²) O(n) two pointers
49 Group Anagrams Sorting + hash table O(n · k log k) O(n · k) hash table
128 Longest Consecutive Sequence Hash set O(n) O(n) hash set
283 Move Zeroes Two pointers O(n) O(1) in-place two pointers

n is the input length and k is the maximum string length where applicable. Space complexity excludes the returned result.

Run a Solution

The solutions use only the Python standard library and require Python 3.9 or newer.

python3 "15. 三数之和/foranddoublepointer.py"

Every solution file includes an if __name__ == "__main__" example, so it can be run directly without additional setup.

Repository Structure

leetcode-sdp/
├── 01.两数之和/
│   ├── doubleforloop.py
│   └── hashtable.py
├── 3. 无重复字符的最长子串/
│   └── Slidingwindows.py
└── ...

Problems are grouped by LeetCode number and title. When a problem has multiple useful approaches, each approach is kept in a separate implementation file for comparison.

Learning Focus

  • Choosing the simplest data structure that fits the problem
  • Recognizing hash table, sliding window, and two-pointer patterns
  • Comparing straightforward and optimized approaches
  • Recording time and space trade-offs alongside the implementation

This repository is intentionally small and readable. New solutions will be added as they are reviewed and verified.

About

Python solutions for selected LeetCode problems.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages