Skip to content

whisperpine/leetcode-py

LeetCode Python

An ongoing list of LeetCode problem solutions in Python.

NeetCode Roadmap

Refer to NeetCode Roadmap.

Get Started

Solutions for LeetCode problems are written in files under ./tests respectively. This means that pytest can run test cases for a specific LeetCode problem. But for comprehensive tests, you should copy the code to LeetCode live editor and submit. See LeetCode problem set.

There are several ways to run tests:

# Run all test cases.
pytest
# Run test cases in a given file.
pytest path/to/test_file.py
# Run a specific test case in a given file.
pytest path/to/test_file.py::test_function_name

Table of Problems

Array & Hash

Problem Difficulty Solution
1. Two Sum Easy 1_two_sum.py
217. Contains Duplicate Easy 217_contains_duplicate.py
242. Valid Anagram Easy 242_valid_anagram.py
49. Group Anagrams Medium 49_group_anagrams.py
347. Top K Frequent Elements Medium 347_top_k_frequent_elements.py
238. Product of Array Except Self Medium 238_product_of_array_except_self.py
128. Longest Consecutive Sequence Medium 128_longest_consecutive_sequence.py

Two Pointers

Problem Difficulty Solution
125. Valid Palindrome Easy 125_valid_palindrome.py
15. 3Sum Medium 15_3sum.py

Stack

Problem Difficulty Solution
20. Valid Parentheses Easy 20_valid_parentheses.py

Binary Search

Problem Difficulty Solution
704. Binary Search Easy 704_binary_search.py
74. Search a 2D Matrix Medium 74_search_a_2d_matrix.py

Sliding Window

Problem Difficulty Solution
121. Best Time to Buy and Sell Stock Easy 121_best_time_to_buy_and_sell_stock.py
3. Longest Substring Without Repeating Characters Medium 3_longest_substring_without_repeating_characters.py

About

LeetCode problem solutions in Rust.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Languages