A repository for practicing LeetCode problems using Python, managed with Poetry.
leetcode-python-practice/
├── solutions/ # Solution files organized by difficulty
│ ├── easy/
│ ├── medium/
│ └── hard/
├── tests/ # Test files for solutions
└── utils/ # Utility functions and helper classes
-
Make sure you have Poetry installed:
curl -sSL https://install.python-poetry.org | python3 - -
Install dependencies:
poetry install
-
Activate the virtual environment:
poetry shell
Each LeetCode solution is organized in its own directory under the appropriate difficulty level with the following structure:
solutions/
└── [difficulty]/
└── [problem-number]-[problem-name]/
├── README.md # Problem description, approach, and complexity analysis
├── solution.py # Solution implementation
└── test_solution.py # Test cases
- Copy the template from
solutions/problem_template/to create a new solution:cp -r solutions/problem_template solutions/[difficulty]/[name]_[number]
- Fill in the problem details in README.md
- Implement your solution in solution.py
- Add test cases in test_solution.py
- Run tests:
poetry run pytest solutions/[difficulty]/[name]_[number]/test_solution.py
This project uses Black for code formatting and isort for import sorting:
poetry run black .
poetry run isort .Run Flake8 for code linting:
poetry run flake8- Python 3.9+
- pytest for testing
- black for code formatting
- isort for import sorting
- flake8 for linting