{"id":18719229,"url":"https://github.com/fbjorn/leetcode-runner","last_synced_at":"2025-04-12T14:07:55.243Z","repository":{"id":62575493,"uuid":"434208662","full_name":"fbjorn/leetcode-runner","owner":"fbjorn","description":"Quick dive into LeetCode problem solving 🧠","archived":false,"fork":false,"pushed_at":"2023-06-29T10:39:41.000Z","size":69,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T08:47:33.439Z","etag":null,"topics":["leetcode","leetcode-python","leetcode-solutions"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fbjorn.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-02T12:16:37.000Z","updated_at":"2023-09-17T13:57:46.000Z","dependencies_parsed_at":"2022-11-03T18:54:39.051Z","dependency_job_id":null,"html_url":"https://github.com/fbjorn/leetcode-runner","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fbjorn%2Fleetcode-runner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fbjorn%2Fleetcode-runner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fbjorn%2Fleetcode-runner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fbjorn%2Fleetcode-runner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fbjorn","download_url":"https://codeload.github.com/fbjorn/leetcode-runner/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248530609,"owners_count":21119601,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["leetcode","leetcode-python","leetcode-solutions"],"created_at":"2024-11-07T13:24:42.947Z","updated_at":"2025-04-12T14:07:55.221Z","avatar_url":"https://github.com/fbjorn.png","language":"Python","readme":"# Overview\n\n[![PyPI Version](https://img.shields.io/pypi/v/leetcode-runner.svg)](https://pypi.org/project/leetcode-runner)\n[![PyPI License](https://img.shields.io/pypi/l/leetcode-runner.svg)](https://pypi.org/project/leetcode-runner)\n\n[LeetCode](leetcode.com) is an excellent platform to practice your algorithm solving skills, but coding in their web editor isn't super convenient.\n\nMost likely, you develop solutions in your IDE and run the program several times with different inputs before submitting it, right?\n\nWhat if you had a CLI utility that would offer:\n- Ready-to-run python file with a correct `Solution` placeholder\n- Problem description inside the same file\n- Built-in Input / Output examples\n- Neat test runner\n\nIn other words you don't need to copy anything from leetcode. Just a single command and you're ready to rock 🧠\n\nInterested? Welcome!\n\n# Installation\n\nInstall it directly into an activated virtual environment:\n\n```text\n$ pip install leetcode-runner\n```\n\nor add it to your [Poetry](https://poetry.eustace.io/) project:\n\n```text\n$ poetry add leetcode-runner\n```\n\n# Usage\n\n1. Install the library from PyPi\n2. Go to [LeetCode](https://leetcode.com) and pick a problem to solve\n3. Copy the title slug from the URL (e.g `is-subsequence`) and execute in your terminal:\n\n   ```shell\n   leetcode pull is-subsequence\n   ```\n\nIt will create a file called `392-is-subsequence.py` and you can start coding straight\naway!\n\n```shell\npython 392-is-subsequence.py\n# or like this, depends on how you manage your python\npoetry run python 392-is-subsequence.py\n\n------------------------------\n[ FAILED ]\ns = \"abc\", t = \"ahbgdc\"\nExpected: True\nActual  : None\n------------------------------\n[ FAILED ]\ns = \"axc\", t = \"ahbgdc\"\nExpected: False\nActual  : None\n\nPassed: 0/2\n```\n\nBy default a method `Solution` doesn't do anything, that's why the answer is None. You\nneed to actually solve the problem 😉.\n\nPlease read the next section to undestand how it works and also check the\n[limitations](#limitations) section.\n\n# Usage (manual)\n\nThis is a legacy way to work with this library\n\n1. Install the library from PyPi\n2. Go to [LeetCode](https://leetcode.com) and pick a problem to solve\n3. Open your favourite IDE and import the `leetcode_runner`\n4. Copy problem samples into some variable, like a `problem`, and copy the base\n   `Solution` class that LeetCode provides\n5. `LeetCode(problem, Solution).check()` will run these samples!\n6. Pass your own samples into `check` function\n\n```py\nfrom leetcode_runner import LeetCode, TestCase, Args\nfrom typing import *\n\n# Copied as is from the LeetCode\nproblem = \"\"\"\nExample 1:\n\nInput: nums = [2,7,11,15], target = 9\nOutput: [0,1]\nOutput: Because nums[0] + nums[1] == 9, we return [0, 1].\nExample 2:\n\nInput: nums = [3,2,4], target = 6\nOutput: [1,2]\nExample 3:\n\nInput: nums = [3,3], target = 6\nOutput: [0,1]\n\"\"\"\n\nclass Solution:\n    def twoSum(self, nums: List[int], target: int) -\u003e List[int]:\n        return [1, 2]\n\nLeetCode(problem, Solution).check()\n```\n\nWill print:\n\n```text\n------------------------------\n[ FAILED ]\nnums = [2,7,11,15], target = 9\nExpected: [0, 1]\nActual  : [1, 2]\n------------------------------\n[ OK ]\nnums = [3,2,4], target = 6\nExpected: [1, 2]\nActual  : [1, 2]\n------------------------------\n[ FAILED ]\nnums = [3,3], target = 6\nExpected: [0, 1]\nActual  : [1, 2]\n\nPassed: 1/3\n```\n\nProviding custom cases is also possible:\n\n```python\n\nlc = LeetCode(problem, Solution)\n\nlc.check(\n    extra_cases=[\n        TestCase(args=Args(nums=[0, 1, 2], target=3), answer=[1, 2]),\n        # or\n        TestCase(Args(nums=[0, 1], target=1), [0, 1])\n    ]\n)\n\n```\n\n## Code snippet\n\nJust copy \u0026 paste this in your IDE and start coding:\n\n```python\nfrom leetcode_runner import LeetCode, TestCase, Args\nfrom typing import *\n\nPROBLEM = \"\"\"\n\n\"\"\"\n\n\nclass Solution:\n    pass\n\n\nLeetCode(PROBLEM, Solution).check(\n    extra_cases=[\n\n    ]\n)\n\n```\n\n# Requirements\n\n- Python 3.9+\n\n# Limitations\n\n- Runner supports python only\n- This tool uses Leetcode's GraphQL API under the hood, I'm not sure how long it will be\n  available for public usage\n- This tool can download only public problems. Subscription-based require authentication\n  that is currently not implemented\n\n---\n\nThis project was generated with [cookiecutter](https://github.com/audreyr/cookiecutter)\nusing [jacebrowning/template-python](https://github.com/jacebrowning/template-python).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffbjorn%2Fleetcode-runner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffbjorn%2Fleetcode-runner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffbjorn%2Fleetcode-runner/lists"}