LeetCode solutions runner
Project description
Overview
LeetCode solutions runner
Usage
- Install the library from PyPi
- Go to LeetCode and pick a problem to solve
- Open your favourite IDE and import the
leetcode_runner
- Copy a problem samples into some variable, like a
problem
, and copy the baseSolution
class that LeetCode provides LeetCode(problem, Solution).check()
will run these samples!- Pass your own samples into
check
function
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])
]
)
Requirements
- Python 3.9+
Installation
Install it directly into an activated virtual environment:
$ pip install leetcode-runner
or add it to your Poetry project:
$ poetry add leetcode-runner
This project was generated with cookiecutter using jacebrowning/template-python.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
leetcode-runner-0.0.3.tar.gz
(4.8 kB
view hashes)
Built Distribution
Close
Hashes for leetcode_runner-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5bc4a251af317037b294eaff8097fdca90738ad09d9bf947963438ba02a9e15d |
|
MD5 | 0d374659da7377523310376d0ad020e6 |
|
BLAKE2b-256 | a499e0282e6295027f5ca3c5368ed2e3ad641de5009736c2090e1755de1f59e3 |