This repo stores solutions to questions on LeetCode that I did for practice. If you are only looking for "How to Run" instructions please feel free to skip ahead to the How to run code section. Original questions, examples and constraints can be found on the LeetCode website. Solutions based on other people's solutions are cited in the same file usually at the top of the function in a comment.
I have created a top level folder for each language in which I have solutions. I am learning rust and intend to use this as a way to explore the language. Then under each language there are some helper files to provide commonly reused code, these are liable to change as I discover more of what is common among LeetCode problems. Other than the helper files there is one file per problem in the folder. I tried to keep naming of the files obvious. The format may need to be language specific. For python the name cannot start with a number so an it is prefixed with an underscore then the problem number then an underscore followed by the name with all spaces removed.
I've tried to keep it as simple as possible but also wanted to minimize required repeated work, as a result some steps are designed with IDE support in mind, like dependency importing. All commands are expected to be run from the root folder of the repository where "README.md" is found.
Language:
Assumption: Both pip and python 3.6 or greater are already installed.
- Install dependencies:
pip install -r requirements.txt
- Link main.py to problem
- Uncomment "tester" function call
- Add import for tester from desired problem e.g.
from python3._1_TwoSum import tester
- Execute run.py
python3 run.py
Should show output that it was run and how long it took
Language
- Create file for problem in python3 folder
- Copy starter code from LeetCode into file (optionally add pass to clear errors)
- Copy starter tester code into newly created file from main (can be identified as commented out as a string at bottom of the file)
- Import helper library
- Fill in starter code with problem number and other required parameters (parameters can be seen in helper file).
- Fill in example test cases
- Some problems may require input transformation, simply call a function to transform the input so that your solution gets the input in the right format e.g. convert an integer list to tree as seen in problem 1302
- Some problems allow multiple solutions those often need to be handled on a case by case basis but in general if the output is an unordered list you can find an example in problem 47
- Now you can implement your solution and test and debug locally.