Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 60 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,60 @@
# leetcode
# LeetCode Python Solutions

A collection of LeetCode problem solutions implemented in Python with detailed complexity analysis and test coverage.

## Features

- **Python Solutions**: All solutions written in Python 3
- **Testing**: pytest test coverage for all solutions
- **Complexity Analysis**: Detailed time and space complexity documentation for each solution
- **Organized Structure**: Problems organized by difficulty level (Easy, Medium, Hard)

## Migration Status

🔄 **Currently migrating from old structure to new directory structure**

This project is being reorganized. The following problems have been migrated to the new structure:

- ✅ Migrated problems in `problems/` directory (83 problems listed below)
- ⏳ Legacy problems still being migrated

## Project Structure

```
leetcode/
├── problems/
│ ├── easy/ # Easy difficulty problems
│ ├── medium/ # Medium difficulty problems
│ └── hard/ # Hard difficulty problems
├── docs/ # Detailed problem lists by difficulty
├── tests/ # Test utilities and fixtures
└── utils/ # Shared utilities and helpers
```

Each problem follows this structure:
```
{difficulty}/{problem-name}_{number}/
├── solution.py # Solution implementation
├── test_solution.py # Test cases
└── __init__.py # Package initialization
```

## Solutions

📊 **Statistics**: 83 problems solved (migrated to new structure)

| Difficulty | Count |
|------------|-------|
| Easy | 58 |
| Medium | 24 |
| Hard | 1 |

### Browse by Difficulty

- 📗 [Easy Problems](docs/EASY.md)
- 📘 [Medium Problems](docs/MEDIUM.md)
- 📕 [Hard Problems](docs/HARD.md)

## Author

[Peter Chen](https://github.com/kobukuro)
70 changes: 70 additions & 0 deletions docs/EASY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Easy Problems

Total: 58 problems solved

## Solutions

| # | Title | Solution | Tests |
|---|-------|----------|-------|
| 1 | [Two Sum](https://leetcode.com/problems/two-sum/) | [solution.py](../problems/easy/two_sum_1/solution.py) | [test_solution.py](../problems/easy/two_sum_1/test_solution.py) |
| 20 | [Valid Parentheses](https://leetcode.com/problems/valid-parentheses/) | [solution.py](../problems/easy/valid_parentheses_20/solution.py) | [test_solution.py](../problems/easy/valid_parentheses_20/test_solution.py) |
| 21 | [Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/) | [solution.py](../problems/easy/merge_two_sorted_lists_21/solution.py) | [test_solution.py](../problems/easy/merge_two_sorted_lists_21/test_solution.py) |
| 26 | [Remove Duplicates from Sorted Array](https://leetcode.com/problems/remove-duplicates-from-sorted-array/) | [solution.py](../problems/easy/remove_duplicates_from_sorted_array_26/solution.py) | [test_solution.py](../problems/easy/remove_duplicates_from_sorted_array_26/test_solution.py) |
| 58 | [Length of Last Word](https://leetcode.com/problems/length-of-last-word/) | [solution.py](../problems/easy/length_of_last_word_58/solution.py) | [test_solution.py](../problems/easy/length_of_last_word_58/test_solution.py) |
| 70 | [Climbing Stairs](https://leetcode.com/problems/climbing-stairs/) | [solution.py](../problems/easy/climbing_stairs_70/solution.py) | [test_solution.py](../problems/easy/climbing_stairs_70/test_solution.py) |
| 88 | [Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array/) | [solution.py](../problems/easy/merge_sorted_array_88/solution.py) | [test_solution.py](../problems/easy/merge_sorted_array_88/test_solution.py) |
| 100 | [Same Tree](https://leetcode.com/problems/same-tree/) | [solution.py](../problems/easy/same_tree_100/solution.py) | [test_solution.py](../problems/easy/same_tree_100/test_solution.py) |
| 104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree/) | [solution.py](../problems/easy/maximum_depth_of_binary_tree_104/solution.py) | [test_solution.py](../problems/easy/maximum_depth_of_binary_tree_104/test_solution.py) |
| 112 | [Path Sum](https://leetcode.com/problems/path-sum/) | [solution.py](../problems/easy/path_sum_112/solution.py) | [test_solution.py](../problems/easy/path_sum_112/test_solution.py) |
| 141 | [Linked List Cycle](https://leetcode.com/problems/linked-list-cycle/) | [solution.py](../problems/easy/linked_list_cycle_141/solution.py) | [test_solution.py](../problems/easy/linked_list_cycle_141/test_solution.py) |
| 191 | [Number of 1 Bits](https://leetcode.com/problems/number-of-1-bits/) | [solution.py](../problems/easy/number_of_1_bits_191/solution.py) | [test_solution.py](../problems/easy/number_of_1_bits_191/test_solution.py) |
| 206 | [Reverse Linked List](https://leetcode.com/problems/reverse-linked-list/) | [solution.py](../problems/easy/reverse_linked_list_206/solution.py) | [test_solution.py](../problems/easy/reverse_linked_list_206/test_solution.py) |
| 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate/) | [solution.py](../problems/easy/contains_duplicate_217/solution.py) | [test_solution.py](../problems/easy/contains_duplicate_217/test_solution.py) |
| 226 | [Invert Binary Tree](https://leetcode.com/problems/invert-binary-tree/) | [solution.py](../problems/easy/invert_binary_tree_226/solution.py) | [test_solution.py](../problems/easy/invert_binary_tree_226/test_solution.py) |
| 242 | [Valid Anagram](https://leetcode.com/problems/valid-anagram/) | [solution.py](../problems/easy/valid_anagram_242/solution.py) | [test_solution.py](../problems/easy/valid_anagram_242/test_solution.py) |
| 344 | [Reverse String](https://leetcode.com/problems/reverse-string/) | [solution.py](../problems/easy/reverse_string_344/solution.py) | [test_solution.py](../problems/easy/reverse_string_344/test_solution.py) |
| 345 | [Reverse Vowels of a String](https://leetcode.com/problems/reverse-vowels-of-a-string/) | [solution.py](../problems/easy/reverse_vowels_of_a_string_345/solution.py) | [test_solution.py](../problems/easy/reverse_vowels_of_a_string_345/test_solution.py) |
| 383 | [Ransom Note](https://leetcode.com/problems/ransom-note/) | [solution.py](../problems/easy/ransom_note_383/solution.py) | [test_solution.py](../problems/easy/ransom_note_383/test_solution.py) |
| 387 | [First Unique Character in a String](https://leetcode.com/problems/first-unique-character-in-a-string/) | [solution.py](../problems/easy/first_unique_character_in_a_string_387/solution.py) | [test_solution.py](../problems/easy/first_unique_character_in_a_string_387/test_solution.py) |
| 412 | [Fizz Buzz](https://leetcode.com/problems/fizz-buzz/) | [solution.py](../problems/easy/fizz_buzz_412/solution.py) | [test_solution.py](../problems/easy/fizz_buzz_412/test_solution.py) |
| 509 | [Fibonacci Number](https://leetcode.com/problems/fibonacci-number/) | [solution.py](../problems/easy/fibonacci_number_509/solution.py) | [test_solution.py](../problems/easy/fibonacci_number_509/test_solution.py) |
| 557 | [Reverse Words in a String III](https://leetcode.com/problems/reverse-words-in-a-string-iii/) | [solution.py](../problems/easy/reverse_words_in_a_string_III_557/solution.py) | [test_solution.py](../problems/easy/reverse_words_in_a_string_III_557/test_solution.py) |
| 572 | [Subtree of Another Tree](https://leetcode.com/problems/subtree-of-another-tree/) | [solution.py](../problems/easy/subtree_of_another_tree_572/solution.py) | [test_solution.py](../problems/easy/subtree_of_another_tree_572/test_solution.py) |
| 700 | [Search in a Binary Search Tree](https://leetcode.com/problems/search-in-a-binary-search-tree/) | [solution.py](../problems/easy/search_in_a_binary_search_tree_700/solution.py) | [test_solution.py](../problems/easy/search_in_a_binary_search_tree_700/test_solution.py) |
| 704 | [Binary Search](https://leetcode.com/problems/binary-search/) | [solution.py](../problems/easy/binary_search_704/solution.py) | [test_solution.py](../problems/easy/binary_search_704/test_solution.py) |
| 709 | [To Lower Case](https://leetcode.com/problems/to-lower-case/) | [solution.py](../problems/easy/to_lower_case_709/solution.py) | [test_solution.py](../problems/easy/to_lower_case_709/test_solution.py) |
| 771 | [Jewels and Stones](https://leetcode.com/problems/jewels-and-stones/) | [solution.py](../problems/easy/jewels_and_stones_771/solution.py) | [test_solution.py](../problems/easy/jewels_and_stones_771/test_solution.py) |
| 804 | [Unique Morse Code Words](https://leetcode.com/problems/unique-morse-code-words/) | [solution.py](../problems/easy/unique_morse_code_words_804/solution.py) | [test_solution.py](../problems/easy/unique_morse_code_words_804/test_solution.py) |
| 977 | [Squares of a Sorted Array](https://leetcode.com/problems/squares-of-a-sorted-array/) | [solution.py](../problems/easy/squares_of_a_sorted_array_977/solution.py) | [test_solution.py](../problems/easy/squares_of_a_sorted_array_977/test_solution.py) |
| 1119 | [Remove Vowels from a String](https://leetcode.com/problems/remove-vowels-from-a-string/) | [solution.py](../problems/easy/remove_vowels_from_a_string_1119/solution.py) | [test_solution.py](../problems/easy/remove_vowels_from_a_string_1119/test_solution.py) |
| 1160 | [Find Words That Can Be Formed by Characters](https://leetcode.com/problems/find-words-that-can-be-formed-by-characters/) | [solution.py](../problems/easy/find_words_that_can_be_formed_by_characters_1160/solution.py) | [test_solution.py](../problems/easy/find_words_that_can_be_formed_by_characters_1160/test_solution.py) |
| 1323 | [Maximum 69 Number](https://leetcode.com/problems/maximum-69-number/) | [solution.py](../problems/easy/maximum_69_number_1323/solution.py) | [test_solution.py](../problems/easy/maximum_69_number_1323/test_solution.py) |
| 1365 | [How Many Numbers Are Smaller Than the Current Number](https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number/) | [solution.py](../problems/easy/how_many_numbers_are_smaller_than_the_current_number_1365/solution.py) | [test_solution.py](../problems/easy/how_many_numbers_are_smaller_than_the_current_number_1365/test_solution.py) |
| 1389 | [Create Target Array in the Given Order](https://leetcode.com/problems/create-target-array-in-the-given-order/) | [solution.py](../problems/easy/create_target_array_in_the_given_order_1389/solution.py) | [test_solution.py](../problems/easy/create_target_array_in_the_given_order_1389/test_solution.py) |
| 1431 | [Kids With the Greatest Number of Candies](https://leetcode.com/problems/kids-with-the-greatest-number-of-candies/) | [solution.py](../problems/easy/kids_with_the_greatest_number_of_candies_1431/solution.py) | [test_solution.py](../problems/easy/kids_with_the_greatest_number_of_candies_1431/test_solution.py) |
| 1436 | [Destination City](https://leetcode.com/problems/destination-city/) | [solution.py](../problems/easy/destination_city_1436/solution.py) | [test_solution.py](../problems/easy/destination_city_1436/test_solution.py) |
| 1603 | [Design Parking System](https://leetcode.com/problems/design-parking-system/) | [solution.py](../problems/easy/design_parking_system_1603/solution.py) | [test_solution.py](../problems/easy/design_parking_system_1603/test_solution.py) |
| 1662 | [Check If Two String Arrays Are Equivalent](https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/) | [solution.py](../problems/easy/check_if_two_string_arrays_are_equivalent_1662/solution.py) | [test_solution.py](../problems/easy/check_if_two_string_arrays_are_equivalent_1662/test_solution.py) |
| 1672 | [Richest Customer Wealth](https://leetcode.com/problems/richest-customer-wealth/) | [solution.py](../problems/easy/richest_customer_wealth_1672/solution.py) | [test_solution.py](../problems/easy/richest_customer_wealth_1672/test_solution.py) |
| 1773 | [Count Items Matching a Rule](https://leetcode.com/problems/count-items-matching-a-rule/) | [solution.py](../problems/easy/count_items_matching_a_rule_1773/solution.py) | [test_solution.py](../problems/easy/count_items_matching_a_rule_1773/test_solution.py) |
| 1816 | [Truncate Sentence](https://leetcode.com/problems/truncate-sentence/) | [solution.py](../problems/easy/truncate_sentence_1816/solution.py) | [test_solution.py](../problems/easy/truncate_sentence_1816/test_solution.py) |
| 1929 | [Concatenation of Array](https://leetcode.com/problems/concatenation-of-array/) | [solution.py](../problems/easy/concatenation_of_array_1929/solution.py) | [test_solution.py](../problems/easy/concatenation_of_array_1929/test_solution.py) |
| 1941 | [Check if All Characters Have Equal Number of Occurrences](https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/) | [solution.py](../problems/easy/CheckIfAllCharactersHaveEqualNumberOfOccurrences1941/solution.py) | [test_solution.py](../problems/easy/CheckIfAllCharactersHaveEqualNumberOfOccurrences1941/test_solution.py) |
| 2011 | [Final Value of Variable After Performing Operations](https://leetcode.com/problems/final-value-of-variable-after-performing-operations/) | [solution.py](../problems/easy/final_value_of_variable_after_performing_operations_2011/solution.py) | [test_solution.py](../problems/easy/final_value_of_variable_after_performing_operations_2011/test_solution.py) |
| 2057 | [Smallest Index With Equal Value](https://leetcode.com/problems/smallest-index-with-equal-value/) | [solution.py](../problems/easy/smallest_index_with_equal_value_2057/solution.py) | [test_solution.py](../problems/easy/smallest_index_with_equal_value_2057/test_solution.py) |
| 2114 | [Maximum Number of Words Found in Sentences](https://leetcode.com/problems/maximum-number-of-words-found-in-sentences/) | [solution.py](../problems/easy/maximum_number_of_words_found_in_sentences_2114/solution.py) | [test_solution.py](../problems/easy/maximum_number_of_words_found_in_sentences_2114/test_solution.py) |
| 2124 | [Check if All A's Appears Before All B's](https://leetcode.com/problems/check-if-all-as-appears-before-all-bs/) | [solution.py](../problems/easy/check_if_all_a_s_appears_before_all_b_s_2124/solution.py) | [test_solution.py](../problems/easy/check_if_all_a_s_appears_before_all_b_s_2124/test_solution.py) |
| 2129 | [Capitalize the Title](https://leetcode.com/problems/capitalize-the-title/) | [solution.py](../problems/easy/capitalize_the_title_2129/solution.py) | [test_solution.py](../problems/easy/capitalize_the_title_2129/test_solution.py) |
| 2185 | [Counting Words With a Given Prefix](https://leetcode.com/problems/counting-words-with-a-given-prefix/) | [solution.py](../problems/easy/counting_words_with_a_given_prefix_2185/solution.py) | [test_solution.py](../problems/easy/counting_words_with_a_given_prefix_2185/test_solution.py) |
| 2215 | [Find the Difference of Two Arrays](https://leetcode.com/problems/find-the-difference-of-two-arrays/) | [solution.py](../problems/easy/find_the_difference_of_two_arrays_2215/solution.py) | [test_solution.py](../problems/easy/find_the_difference_of_two_arrays_2215/test_solution.py) |
| 2315 | [Count Asterisks](https://leetcode.com/problems/count-asterisks/) | [solution.py](../problems/easy/count_asterisks_2315/solution.py) | [test_solution.py](../problems/easy/count_asterisks_2315/test_solution.py) |
| 2469 | [Convert the Temperature](https://leetcode.com/problems/convert-the-temperature/) | [solution.py](../problems/easy/convert_the_temperature_2469/solution.py) | [test_solution.py](../problems/easy/convert_the_temperature_2469/test_solution.py) |
| 2710 | [Remove Trailing Zeros From a String](https://leetcode.com/problems/remove-trailing-zeros-from-a-string/) | [solution.py](../problems/easy/remove_trailing_zeros_from_a_string_2710/solution.py) | [test_solution.py](../problems/easy/remove_trailing_zeros_from_a_string_2710/test_solution.py) |
| 2798 | [Number of Employees Who Met the Target](https://leetcode.com/problems/number-of-employees-who-met-the-target/) | [solution.py](../problems/easy/number_of_employees_who_met_the_target_2798/solution.py) | [test_solution.py](../problems/easy/number_of_employees_who_met_the_target_2798/test_solution.py) |
| 2942 | [Find Words Containing Character](https://leetcode.com/problems/find-words-containing-character/) | [solution.py](../problems/easy/find_words_containing_character_2942/solution.py) | [test_solution.py](../problems/easy/find_words_containing_character_2942/test_solution.py) |
| 3110 | [Score of a String](https://leetcode.com/problems/score-of-a-string/) | [solution.py](../problems/easy/score_of_a_string_3110/solution.py) | [test_solution.py](../problems/easy/score_of_a_string_3110/test_solution.py) |
| 3289 | [The Two Sneaky Numbers of Digitville](https://leetcode.com/problems/the-two-sneaky-numbers-of-digitville/) | [solution.py](../problems/easy/the_two_sneaky_numbers_of_digitville_3289/solution.py) | [test_solution.py](../problems/easy/the_two_sneaky_numbers_of_digitville_3289/test_solution.py) |

---

[← Back to Main README](../README.md)
13 changes: 13 additions & 0 deletions docs/HARD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Hard Problems

Total: 1 problem solved

## Solutions

| # | Title | Solution | Tests |
|---|-------|----------|-------|
| 329 | [Longest Increasing Path in a Matrix](https://leetcode.com/problems/longest-increasing-path-in-a-matrix/) | [solution.py](../problems/hard/longest_increasing_path_in_a_matrix_329/solution.py) | [test_solution.py](../problems/hard/longest_increasing_path_in_a_matrix_329/test_solution.py) |

---

[← Back to Main README](../README.md)
Loading
Loading