Overview
LeetCode solutions runner
Installation
Install it directly into an activated virtual environment:
$ pip install leetcode-runner
or add it to your Poetry project:
$ poetry add leetcode-runner
Usage
-
Install the library from PyPi
-
Go to LeetCode and pick a problem to solve
-
Copy the title slug from the URL (e.g
is-subsequence) and execute in your terminal:leetcode pull is-subsequence
It will create a file called 392-is-subsequence.py and you can start coding straight
away!
python 392-is-subsequence.py
# or like this, depends on how you manage your python
poetry run python 392-is-subsequence.py
------------------------------
[ FAILED ]
s = "abc", t = "ahbgdc"
Expected: True
Actual : None
------------------------------
[ FAILED ]
s = "axc", t = "ahbgdc"
Expected: False
Actual : None
Passed: 0/2
By default a method Solution doesn't do anything, that's why the answer is None. You
need to actually solve the problem 😉.
Please read the next section to undestand how it works and also check the limitations section.
Usage (manual)
This is a legacy way to work with this library
- Install the library from PyPi
- Go to LeetCode and pick a problem to solve
- Open your favourite IDE and import the
leetcode_runner - Copy problem samples into some variable, like a
problem, and copy the baseSolutionclass that LeetCode provides LeetCode(problem, Solution).check()will run these samples!- Pass your own samples into
checkfunction
from leetcode_runner import LeetCode, TestCase, Args
from typing import *
# Copied as is from the LeetCode
problem = """
Example 1:
Input: nums = [2,7,11,15], target = 9
Output: [0,1]
Output: Because nums[0] + nums[1] == 9, we return [0, 1].
Example 2:
Input: nums = [3,2,4], target = 6
Output: [1,2]
Example 3:
Input: nums = [3,3], target = 6
Output: [0,1]
"""
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
return [1, 2]
LeetCode(problem, Solution).check()
Will print:
------------------------------
[ FAILED ]
nums = [2,7,11,15], target = 9
Expected: [0, 1]
Actual : [1, 2]
------------------------------
[ OK ]
nums = [3,2,4], target = 6
Expected: [1, 2]
Actual : [1, 2]
------------------------------
[ FAILED ]
nums = [3,3], target = 6
Expected: [0, 1]
Actual : [1, 2]
Passed: 1/3
Providing custom cases is also possible:
lc = LeetCode(problem, Solution)
lc.check(
extra_cases=[
TestCase(args=Args(nums=[0, 1, 2], target=3), answer=[1, 2]),
# or
TestCase(Args(nums=[0, 1], target=1), [0, 1])
]
)
Code snippet
Just copy & paste this in your IDE and start coding:
from leetcode_runner import LeetCode, TestCase, Args
from typing import *
PROBLEM = """
"""
class Solution:
pass
LeetCode(PROBLEM, Solution).check(
extra_cases=[
]
)
Requirements
- Python 3.9+
Limitations
- This tool uses Leetcode's GraphQL API under the hood, I'm not sure how long will it be available for public usage
- This tool can download only public problems. Subscription-based requires authentication that is currently not implemented
This project was generated with cookiecutter using jacebrowning/template-python.
Release files for leetcode-runner 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| leetcode-runner-0.0.4.tar.gz | 7.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| leetcode_runner-0.0.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.5 kB
Release files / leetcode-runner-0.0.4.tar.gz
| Download URL | leetcode-runner-0.0.4.tar.gz |
|---|---|
| Size | 7.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
928005bdaa9bbf16ec233a97e316c19d2a5a2acea8993cc0d79e15761d345907
|
|
BLAKE2b-256 checksum How to use checksums |
ce46c6cafaaa0435a7e569ab3570e3755820f127dd14728012a35f803eee8b42
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.13 CPython/3.10.2 Darwin/20.6.0
|
Release files / leetcode_runner-0.0.4-py3-none-any.whl
| Download URL | leetcode_runner-0.0.4-py3-none-any.whl |
|---|---|
| Size | 8.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a80d80392043c1040951f9ed39a0a1885d6241634835c73eb6d4cb7460038a16
|
|
BLAKE2b-256 checksum How to use checksums |
2183709370cce8cd1bf1b59c3b3a4d6d7b8c0e79b2e4a9063e51a9aa97c12fd2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.13 CPython/3.10.2 Darwin/20.6.0
|