A collection of efficient and well-commented Python solutions for popular LeetCode problems. Each file is named after its corresponding LeetCode problem for easy reference.
- Each file is named as
<problem_number>_<Problem_Name>.py - Each file contains a single class-based solution, often with time and space complexity analysis in comments.
- Solutions cover a wide range of topics: arrays, strings, dynamic programming, trees, graphs, stacks, queues, and more.
# 53_Maximum_Subarray.py
class Solution:
def maxSubArray(self, nums: List[int]) -> int:
curSum = 0
maxSub = nums[0]
for n in nums:
if curSum < 0:
curSum = 0
curSum += n
maxSub = max(maxSub, curSum)
return maxSub
# time complexity: O(n)
# space complexity: O(1)-
Clone the repository:
git clone https://github.com/AliAoun/LEETCODE-Solutions-py.git cd LEETCODE-Solutions-py -
Browse solutions:
- Find the problem you want by its number or name.
- Open the corresponding
.pyfile for the solution and explanation.
-
Run a solution:
- Copy the class into your local environment or LeetCode editor.
- Add your own test cases as needed.
- Arrays & Strings
- Hashing & Sets
- Two Pointers & Sliding Window
- Binary Search
- Linked Lists
- Trees & Binary Trees
- Dynamic Programming
- Stacks & Queues
- Greedy Algorithms
- Backtracking
- Problems solved:
[number of files] - Language: Python 3
Contributions are welcome! Feel free to open issues or submit pull requests for improvements or new solutions.
This repository is licensed under the MIT License.
- LeetCode for the problems and platform.
- Python community for helpful discussions and resources.
Happy Coding!
My LeetCode Profile: aliaoun