Run LeetCode-style Python solutions against local TOML test cases.
Project description
Leet-Chaser
本地运行 leetcode solution 的命令行框架。
pip 安装运行
python -m pip install leet-chaser
leet-chaser --help
安装后可以直接使用 leet-chaser 命令:
leet-chaser init two-sum
leet-chaser run two-sum
uvx 直接运行
不想把命令安装到当前环境时,可以用 uvx 临时运行:
uvx leet-chaser --help
uvx leet-chaser init two-sum
uvx leet-chaser run two-sum
使用方法
STEP 1: 初始化题目目录
leet-chaser init two-sum
命令会在当前目录创建一个题目文件夹:
two-sum/
├── solution.py
└── cases.toml
STEP 2: 编写 solution.py
from typing import List
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
seen = {}
for index, num in enumerate(nums):
rest = target - num
if rest in seen:
return [seen[rest], index]
seen[num] = index
return []
STEP 3: 填写 cases.toml
entrypoint 是 solution 里的入口方法名。input 是传给入口方法的位置参数数组,output 是期望返回值。
entrypoint = "twoSum"
[[cases]]
input = [[2, 7, 11, 15], 9]
output = [0, 1]
[[cases]]
input = [[3, 2, 4], 6]
output = [1, 2]
[[cases]]
input = [[3, 3], 6]
output = [0, 1]
STEP 4: 运行验证
leet-chaser run two-sum
STEP 5: 调试单个用例
把当前要排查的用例写入 debug.toml,格式和 cases.toml 一致,但只保留一个 [[cases]]:
entrypoint = "twoSum"
[[cases]]
input = [[2, 7, 11, 15], 9]
output = [0, 1]
运行 debug 命令会默认读取当前题目目录下的 debug.toml,并逐行打印入口函数的变量变化:
leet-chaser debug two-sum
leet-chaser debug two-sum -t seen -t rest
leet-chaser debug two-sum -c two-sum/custom-debug.toml
标准示例
仓库内置了 LeetCode 1. Two Sum 的标准示例:
uv run leet-chaser run examples/two-sum
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file leet_chaser-0.1.2.tar.gz.
File metadata
- Download URL: leet_chaser-0.1.2.tar.gz
- Upload date:
- Size: 47.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5521cc5386c080cbff61a41232737ae477f6a135651fe93db879439d16db0ffb
|
|
| MD5 |
6d8a0eeb0f2166b1f6ea61cf59903173
|
|
| BLAKE2b-256 |
553aa711cda84da7015d7c13e918f3ed9c150fc11638ced44312e42ef9598c9d
|
Provenance
The following attestation bundles were made for leet_chaser-0.1.2.tar.gz:
Publisher:
publish.yml on gawainx/leet-chaser
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
leet_chaser-0.1.2.tar.gz -
Subject digest:
5521cc5386c080cbff61a41232737ae477f6a135651fe93db879439d16db0ffb - Sigstore transparency entry: 1496526787
- Sigstore integration time:
-
Permalink:
gawainx/leet-chaser@3ae8ed5d4b8ea1840b2684424ed6bdaa6ae871dd -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/gawainx
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3ae8ed5d4b8ea1840b2684424ed6bdaa6ae871dd -
Trigger Event:
push
-
Statement type:
File details
Details for the file leet_chaser-0.1.2-py3-none-any.whl.
File metadata
- Download URL: leet_chaser-0.1.2-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef18c97c6e17e2fbed6abe49d64911045cec7b67356aff020125e55528d6c5c6
|
|
| MD5 |
479ab4096b0e3d0039aba73c1cfc1790
|
|
| BLAKE2b-256 |
7902dc359a196d5800a525300480450a41be124b4b9c3cb95064a26136f1f876
|
Provenance
The following attestation bundles were made for leet_chaser-0.1.2-py3-none-any.whl:
Publisher:
publish.yml on gawainx/leet-chaser
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
leet_chaser-0.1.2-py3-none-any.whl -
Subject digest:
ef18c97c6e17e2fbed6abe49d64911045cec7b67356aff020125e55528d6c5c6 - Sigstore transparency entry: 1496527244
- Sigstore integration time:
-
Permalink:
gawainx/leet-chaser@3ae8ed5d4b8ea1840b2684424ed6bdaa6ae871dd -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/gawainx
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3ae8ed5d4b8ea1840b2684424ed6bdaa6ae871dd -
Trigger Event:
push
-
Statement type: