https://github.com/fanziyang-v/leetcode
Python implementation for leetcode problems
https://github.com/fanziyang-v/leetcode
leetcode python
Last synced: 7 months ago
JSON representation
Python implementation for leetcode problems
- Host: GitHub
- URL: https://github.com/fanziyang-v/leetcode
- Owner: Fanziyang-v
- Created: 2024-09-12T15:23:04.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-26T13:26:10.000Z (11 months ago)
- Last Synced: 2025-02-01T12:14:31.307Z (9 months ago)
- Topics: leetcode, python
- Language: Python
- Homepage:
- Size: 112 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# leetcode
## Binary Tree
| Problem | Difficulty | Solution |
| ------------------------------------------------------------ | ---------- | ------------------------------------------------------------ |
| [Add One Row to Tree](https://leetcode.cn/problems/add-one-row-to-tree/) | Medium | [add_one_row.py](./binary-tree/add_one_row.py) |
| [Average of Levels in Binary Tree](https://leetcode.cn/problems/average-of-levels-in-binary-tree/) | Easy | [average_of_levels.py](./binary-tree/average_of_levels.py) |
| [Balanced Binary Tree](https://leetcode.cn/problems/balanced-binary-tree/) | Easy | [is_balanced.py](./binary-tree/is_balanced.py) |
| [Binary Search Tree Iterator](https://leetcode.cn/problems/binary-search-tree-iterator/) | Medium | [bst_iterator.py](./binary-tree/bst_iterator.py) |
| [Binary Tree Inorder Traversal](https://leetcode.cn/problems/binary-tree-inorder-traversal/) | Easy | [inorder_traversal.py](./binary-tree/inorder_traversal.py) |
| [Binary Tree Level Order Traversal](https://leetcode.cn/problems/binary-tree-level-order-traversal/) | Medium | [level_order.py](./binary-tree/level_order.py) |
| [Binary Tree Postorder Traversal](https://leetcode.cn/problems/binary-tree-postorder-traversal/) | Easy | [postorder_traversal.py](./binary-tree/postorder_traversal.py) |
| [Binary Tree Preorder Traversal](https://leetcode.cn/problems/binary-tree-preorder-traversal/) | Easy | [preorder_traversal.py](./binary-tree/preorder_traversal.py) |
| [Binary Tree Right Side View](https://leetcode.cn/problems/binary-tree-right-side-view/) | Medium | [right_side_view.py](./binary-tree/right_side_view.py) |
| [Construct Binary Tree from Inorder and Postorder Traversal](https://leetcode.cn/problems/construct-binary-tree-from-inorder-and-postorder-traversal/) | Medium | [build_tree2.py](./binary-tree/build_tree2.py) |
| [Construct Binary Tree from Preorder and Inorder Traversal](https://leetcode.cn/problems/construct-binary-tree-from-preorder-and-inorder-traversal/) | Medium | [build_tree1.py](./binary-tree/build_tree1.py) |
| [Construct Sorted Array to Binary Search Tree](https://leetcode.cn/problems/convert-sorted-array-to-binary-search-tree/) | Medium | [sorted_array2BST.py](./binary-tree/sorted_array2BST.py) |
| [Convert Sorted List to Binary Search Tree](https://leetcode.cn/problems/convert-sorted-list-to-binary-search-tree/) | Medium | [sorted_list2BST.py](./binary-tree/sorted_list2BST.py) |
| [Delete Node in a Binary Search Tree](https://leetcode.cn/problems/delete-node-in-a-bst/) | Medium | [delete_node.py](./binary-tree/delete_node.py) |
| [Find Largest Values in Each Tree Row](https://leetcode.cn/problems/find-largest-value-in-each-tree-row/) | Medium | [largest_values](./binary-tree/largest_values.py) |
| [Flatten Binary Tree To Linked List](https://leetcode.cn/problems/flatten-binary-tree-to-linked-list/) | Medium | [flatten.py](./binary-tree/flatten.py) |
| [Insert into a Binary Search Tree](https://leetcode.cn/problems/insert-into-a-binary-search-tree/) | Medium | [insert_intoBST.py](./binary-tree/insert_intoBST.py) |
| [Invert Binary Tree](https://leetcode.cn/problems/invert-binary-tree/) | Easy | [invert_tree](./binary-tree/invert_tree.py) |
| [Kth Smallest Element in a Binary Search Tree](https://leetcode.cn/problems/kth-smallest-element-in-a-bst/) | Medium | [kth_smallest.py](./binary-tree/kth_smallest.py) |
| [Lowest Common Ancestor of a Binary Tree](https://leetcode.cn/problems/lowest-common-ancestor-of-a-binary-tree/) | Medium | [lowest_common_ancestor.py](./binary-tree/lowest_common_ancestor.py) |
| [Maximum Depth of Binary Tree](https://leetcode.cn/problems/maximum-depth-of-binary-tree/) | Easy | [max_depth.py](./binary-tree/max_depth.py) |
| [Minimum Depth of Binary Tree](https://leetcode.cn/problems/minimum-depth-of-binary-tree/) | Easy | [min_depth.py](./binary-tree/min_depth.py) |
| [Most Frequent Subtree Sum](https://leetcode.cn/problems/most-frequent-subtree-sum/) | Medium | [find_frequent_tree_sum.py](./binary-tree/find_frequent_tree_sum.py) |
| [Path Sum I](https://leetcode.cn/problems/path-sum/) | Medium | [has_path_sum.py](./binary-tree/has_path_sum.py) |
| [Path Sum II](https://leetcode.cn/problems/path-sum-ii/) | Medium | [path_sum.py](./binary-tree/path_sum.py) |
| [Path Sum III](https://leetcode.cn/problems/path-sum-iii/) | Medium | [path_sum2.py](./binary-tree/path_sum2.py) |
| [Recover Binary Search Tree](https://leetcode.cn/problems/recover-binary-search-tree/) | Medium | [recover_tree.py](./binary-tree/recover_tree.py) |
| [Same Tree](https://leetcode.cn/problems/same-tree/) | Easy | [is_same_tree.py](./binary-tree/is_same_tree.py) |
| [Search in a Binary Search Tree](https://leetcode.cn/problems/search-in-a-binary-search-tree/) | Easy | [searchBST.py](./binary-tree/searchBST.py) |
| [Serialize and Deserialize Binary Tree](https://leetcode.cn/problems/serialize-and-deserialize-binary-tree/) | Hard | [codec.py](./binary-tree/codec.py) |
| [Symmetric Tree](https://leetcode.cn/problems/symmetric-tree/) | Easy | [is_symmetric.py](./binary-tree/is_symmetric.py) |
| [Validate Binary Search Tree](https://leetcode.cn/problems/validate-binary-search-tree/) | Medium | [is_validBST.py](./binary-tree/is_validBST.py) |
## Linked List
| Problem | Difficulty | Solution |
| ------------------------------------------------------------ | ---------- | ------------------------------------------------------------ |
| [Convert a Binary Number in a Linked List to Integer](https://leetcode.cn/problems/convert-binary-number-in-a-linked-list-to-integer/) | Easy | [get_decimal_value.py](./linked-list/get_decimal_value.py) |
| [Delete the Middle Node of a Linked List](https://leetcode.cn/problems/delete-the-middle-node-of-a-linked-list/) | Medium | [delete_middle.py](./linked-list/delete_middle.py) |
| [Design Circular Queue](https://leetcode.cn/problems/design-circular-queue/) | Medium | [circular_queue.py](./linked-list/circular_queue.py) |
| [Insert Greatest Common Divisors in Linked List](https://leetcode.cn/problems/insert-greatest-common-divisors-in-linked-list/) | Medium | [insert_greatest_common_divisors.py](./linked-list/insert_greatest_common_divisors.py) |
| [Intersection of Two Linked Lists](https://leetcode.cn/problems/intersection-of-two-linked-lists/) | Easy | [get_intersection_node.py](./linked-list/get_intersection_node.py) |
| [Linked List Cycle](https://leetcode.cn/problems/linked-list-cycle/) | Easy | [has_cycle.py](./linked-list/has_cycle.py) |
| [Linked List Cycle II](https://leetcode.cn/problems/linked-list-cycle-ii/) | Medium | [detect_cycle.py](./linked-list/detect_cycle.py) |
| [LRU Cache](https://leetcode.cn/problems/lru-cache/) | Medium | [lru_cache.py](./linked-list/lru_cache.py) |
| [Merge K Sorted Lists](https://leetcode.cn/problems/merge-k-sorted-lists/) | Hard | [merge_k_lists.py](./linked-list/merge_k_lists.py) |
| [Merge Two Sorted Lists](https://leetcode.cn/problems/merge-two-sorted-lists/) | Easy | [merge_two_lists.py](./linked-list/merge_two_lists.py) |
| [Middle of Linked List](https://leetcode.cn/problems/middle-of-the-linked-list/) | Easy | [middle_node.py](./linked-list/middle_node.py) |
| [Odd Even Linked List](https://leetcode.cn/problems/odd-even-linked-list/) | Medium | [odd_even_list.py](./linked-list/odd_even_list.py) |
| [Palindrome Linked List](https://leetcode.cn/problems/palindrome-linked-list/) | Easy | [is_palindrome.py](./linked-list/is_palindrome.py) |
| [Remove Elements](https://leetcode.cn/problems/remove-linked-list-elements/) | Easy | [remove_elements.py](./linked-list/remove_elements.py) |
| [Remove Nth Node from End of List](https://leetcode.cn/problems/remove-nth-node-from-end-of-list/) | Medium | [remove_nth_from_end.py](./linked-list/remove_nth_from_end.py) |
| [Remove Duplicates from Sorted List](https://leetcode.cn/problems/remove-duplicates-from-sorted-list/) | Easy | [remove_duplicates.py](./linked-list/remove_duplicates.py) |
| [Remove Zero Sum Consecutive Nodes from Linked List](https://leetcode.cn/problems/remove-zero-sum-consecutive-nodes-from-linked-list/) | Medium | [remove_zero_sum_sublists.py](./binary-tree/remove_zero_sum_sublists.py) |
| [Reverse Linked List](https://leetcode.cn/problems/reverse-linked-list/) | Easy | [reverse_list.py](./linked-list/reverse_list.py) |
| [Remove Nodes in Even Length Groups](https://leetcode.cn/problems/reverse-nodes-in-even-length-groups/) | Medium | [remove_even_length_groups.py](./linked-list/remove_even_length_groups.py) |
| [Sort List](https://leetcode.cn/problems/sort-list/) | Medium | [sort_list.py](./linked-list/sort_list.py) |
| [Split Linked List in Parts](https://leetcode.cn/problems/split-linked-list-in-parts/) | Medium | [split_list_to_parts.py](./linked-list/split_list_to_parts.py) |
| [Next Greater Node in Linked List](https://leetcode.cn/problems/next-greater-node-in-linked-list/) | Medium | [next_larger_nodes.py](./linked-list/next_larger_nodes.py) |
## Priority Queue
| Problem | Difficulty | Solution |
| ------------------------------------------------------------ | ---------- | ----------------------------------------------------------- |
| [Find Subsequence of Length K With the Largest Sum](https://leetcode.cn/problems/find-subsequence-of-length-k-with-the-largest-sum/) | Easy | [max_subsequence.py](./priority-queue/max_subsequence.py) |
| [Kth Largest Element in an Array](https://leetcode.cn/problems/kth-largest-element-in-an-array/) | Medium | [find_kth_largest.py](./priority-queue/find_kth_largest.py) |
| [Kth Largest Element in a Stream](https://leetcode.cn/problems/kth-largest-element-in-a-stream/) | Easy | [kth_largest.py](./priority-queue/kth_largest.py) |
| [The K Weakest Rows in a Matrix](https://leetcode.cn/problems/the-k-weakest-rows-in-a-matrix/) | Easy | [k_weakest_row.py](priority-queue/k_weakest_row.py) |
| [Top K Frequent Words](https://leetcode.cn/problems/top-k-frequent-words/) | Medium | [top_k_frequent.py](./priority-queue/top_k_frequent.py) |
## Binary Search
| Problem | Difficulty | Solution |
| ------------------------------------------------------------ | ---------- | ------------------------------------------------------------ |
| [Binary Search](https://leetcode.cn/problems/binary-search/) | Easy | [search.py](./binary-search/search.py) |
| [Find First and Last Position of Element in Sorted Array](https://leetcode.cn/problems/find-first-and-last-position-of-element-in-sorted-array/) | Medium | [search_range.py](./binary-search/search_range.py) |
| [Search in Rotated Sorted Array I](https://leetcode.cn/problems/search-in-rotated-sorted-array/) | Medium | [search_rotated_array.py](./binary-search/search_rotated_array.py) |
| [Search in Rotated Sorted Array II](https://leetcode.cn/problems/search-in-rotated-sorted-array-ii/) | Medium | [search_rotated_array2.py](./binary-search/search_rotated_array2.py) |
| [Missing Number](https://leetcode.cn/problems/missing-number/) | Easy | [find_missing_number.py](./binary-search/find_missing_number.py) |
## Sliding Window
| Problem | Difficulty | Solution |
| ------------------------------------------------------------ | ---------- | ------------------------------------------------------------ |
| [Minimum Size Subarray Sum](https://leetcode.cn/problems/minimum-size-subarray-sum/) | Medium | [min_sub_array_len.py](./sliding-window/min_sub_array_len.py) |
| [Sliding Window Maximum](https://leetcode.cn/problems/sliding-window-maximum/) | Hard | [max_sliding_window.py](./sliding-window/max_sliding_window.py) |
| [Find the Power of K-Size Subarray I](https://leetcode.cn/problems/find-the-power-of-k-size-subarrays-i/) | Medium | [results_array.py](./sliding-window/results_array.py) |
## Dynamic Programming
| Problem | Difficulty | Solution |
| ------------------------------------------------------------ | ---------- | ------------------------------------------------------------ |
| [Coin Change](https://leetcode.cn/problems/coin-change/) | Medium | [coin_change.py](./dynamic-programming/coin_change.py) |
| [Count Sorted Vowel Strings](https://leetcode.cn/problems/count-sorted-vowel-strings/) | Medium | [count_vowel_strings.py](./dynamic-programming/count_vowel_strings.py) |
| [Decode Ways](https://leetcode.cn/problems/decode-ways/) | Medium | [num_decodings.py](./dynamic-programming/num_decodings.py) |
| [Delete Operation for Two Strings](https://leetcode.cn/problems/delete-operation-for-two-strings/) | Medium | [min_distance2.py](./dynamic-programming/min_distance2.py) |
| [Edit Distance](https://leetcode.cn/problems/edit-distance/) | Medium | [min_distance.py](./dynamic-programming/min_distance.py) |
| [Fibonacci Number](https://leetcode.cn/problems/fibonacci-number/) | Easy | [fib.py](./dynamic-programming/fib.py) |
| [House Robber I](https://leetcode.cn/problems/house-robber/) | Medium | [rob1.py](./dynamic-programming/rob1.py) |
| [House Robber II](https://leetcode.cn/problems/house-robber-ii/) | Medium | [rob2.py](./dynamic-programming/rob2.py) |
| [House Robber III](https://leetcode.cn/problems/house-robber-iii/) | Medium | [rob3.py](./dynamic-programming/rob3.py) |
| [Integer Break](https://leetcode.cn/problems/integer-break/) | Medium | [integer_break.py](./dynamic-programming/integer_break.py) |
| [Jump Game I](https://leetcode.cn/problems/jump-game/) | Medium | [can_jump.py](./dynamic-programming/can_jump.py) |
| [Jump Game II](https://leetcode.cn/problems/jump-game-ii/) | Medium | [jump.py](./dynamic-programming/jump.py) |
| [Longest Increasing Subsequence](https://leetcode.cn/problems/longest-increasing-subsequence/) | Medium | [length_of_lis.py](./dynamic-programming/length_of_lis.py) |
| [Longest Palindrome](https://leetcode.cn/problems/longest-palindromic-substring/) | Medium | [longest_palindrome.py](./dynamic-programming/longest_palindrome.py) |
| [Maximal Squares](https://leetcode.cn/problems/maximal-square/) | Medium | [maximal_squares.py](./dynamic-programming/maximal_squares.py) |
| [Maximum Subarray](https://leetcode.cn/problems/maximum-subarray/) | Medium | [max_sub_array.py](./dynamic-programming/max_sub_array.py) |
| [Minimum Path Sum](https://leetcode.cn/problems/minimum-path-sum/) | Medium | [min_path_sum.py](./dynamic-programming/min_path_sum.py) |
| [Minimum Total](https://leetcode.cn/problems/triangle/) | Medium | [minimum_total.py](./dynamic-programming/minimum_total.py) |
| [Pascal's Triangle I](https://leetcode.cn/problems/pascals-triangle/) | Easy | [pasacals_triangle1.py](./dynamic-programming/pascals_triangle1.py) |
| [Pascal's Triangle II](https://leetcode.cn/problems/pascals-triangle-ii/) | Easy | [pasacals_triangle2.py](./dynamic-programming/pascals_triangle2.py) |
| [Perfect Squares](https://leetcode.cn/problems/perfect-squares/) | Medium | [num_sqaures.py](./dynamic-programming/num_squares.py) |
| [Ugly Number II](https://leetcode.cn/problems/ugly-number-ii/) | Medium | [nth_ugly_number.py](./dynamic-programming/nth_ugly_number.py) |
| [Unique Paths I](https://leetcode.cn/problems/unique-paths/) | Medium | [unique_paths.py](./dynamic-programming/unique_paths.py) |
| [Unique Paths II](https://leetcode.cn/problems/unique-paths-ii/) | Medium | [unique_paths_with_obstacles.py](./dynamic-programming/unique_paths_with_obstacles.py) |
| [Wiggle Subsequence](https://leetcode.cn/problems/wiggle-subsequence/) | Medium | [wiggle_max_length.py](./dynamic-programming/wiggle_max_length.py) |
## Combinatorics
| Problem | Difficulty | Solution |
| ------------------------------------------------------------ | ---------- | ------------------------------------------------------------ |
| [Unique Paths](https://leetcode.cn/problems/unique-paths/) | Medium | [unique_paths.py](./combinatorics/unique_paths.py) |
| [Count Numbers with Unique Digits](https://leetcode.cn/problems/count-numbers-with-unique-digits/) | Medium | [count_numbers_with_unique_digits.py](./combinatorics/count_numbers_with_unique_digits.py) |
## Backtrack
| Problem | Difficulty | Solution |
| ------------------------------------------------------------ | ---------- | ------------------------------------------------------------ |
| [Beautiful Arrangement](https://leetcode.cn/problems/beautiful-arrangement/) | Medium | [count_arrangement.py](./backtrack/count_arrangement.py) |
| [Combination Sum](https://leetcode.cn/problems/combination-sum/) | Medium | [combination_sum.py](./backtrack/combination_sum.py) |
| [Letter Combinations of a Phone Number](https://leetcode.cn/problems/letter-combinations-of-a-phone-number/) | Medium | [letter_combinations.py](./backtrack/letter_combinations.py) |
| [N-Queens I](https://leetcode.cn/problems/n-queens/) | Hard | [solve_n_queens1.py](./backtrack/solve_n_queens1.py) |
| [N-Queens II](https://leetcode.cn/problems/n-queens-ii/) | Hard | [solve_n_queens2.py](./backtrack/solve_n_queens2.py) |
| [Permutations](https://leetcode.cn/problems/permutations/) | Medium | [permute.py](./backtrack/permute.py) |
| [Subset I](https://leetcode.cn/problems/subsets/) | Medium | [subset1.py](./backtrack/subset1.py) |
| [Subset II](https://leetcode.cn/problems/subsets-ii/) | Medium | [subset2.py](./backtrack/subset2.py) |
| [Sudoku Solver](https://leetcode.cn/problems/sudoku-solver/) | Hard | [solve_sudoku.py](./backtrack/solve_sudoku.py) |