leetcodelib
📖 简介
leetcodelib 是一个轻量级的 Python 工具库,旨在解决 LeetCode 刷题时本地输入与题目要求数据结构不一致的痛点。
在 LeetCode 上,题目通常以数组(如 [1, 2, 3])的形式给出输入,但算法代码却需要处理 链表 (ListNode) 或 二叉树 (TreeNode) 对象。leetcodelib 提供了高效的序列化与反序列化工具,助你在本地 IDE(如 PyCharm, VS Code)中轻松构建测试用例,享受断点调试的便利。
✨ 为什么选择 leetcodelib?
- 🚀 开箱即用:零依赖,纯 Python 实现,安装即用
- 🌳 完美还原:完美支持 LeetCode 的层序遍历(BFS)二叉树格式(含
null处理) - 🔗 链表神器:一行代码实现数组与链表的相互转换
- ⚡ 调试友好:提供将对象转回数组的函数,方便
print验证结果 - 📝 类型提示:完整的 Type Hinting,让 IDE 智能补全更顺畅
- 🧪 测试覆盖:经过大量边界条件测试(空树、单节点、不平衡树)
🚀 快速开始
安装
pip install leetcodelib
一分钟上手
from leetcodelib import *
# 1. 构造输入:将 LeetCode 数组转为二叉树对象
root = build_tree([3, 9, 20, None, None, 15, 7])
# 2. 构造输入:将 LeetCode 数组转为链表对象
root = build_link_list([3, 9, 1, 2])
Metadata
Release files for leetcodelib 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| leetcodelib-0.1.0.tar.gz | 3.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| leetcodelib-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.0 kB
Release files / leetcodelib-0.1.0.tar.gz
| Download URL | leetcodelib-0.1.0.tar.gz |
|---|---|
| Size | 3.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2e264b02fa5f2df1fd1dc724fddc1d9ba2d6c948849cafa2d7b5010a4b18891c
|
|
BLAKE2b-256 checksum How to use checksums |
5e21cfcfd164c1df439f1d3a843aa3e50871a679f43d57c503e5200613bb66c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 18, 2026.
Transparency logRelease files / leetcodelib-0.1.0-py3-none-any.whl
| Download URL | leetcodelib-0.1.0-py3-none-any.whl |
|---|---|
| Size | 4.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d25fc135365725cbe76a9fe6c86a57bab0707aa84517f851e5c651cb057eaa6f
|
|
BLAKE2b-256 checksum How to use checksums |
ce3e237f99d2d0fa0ea4a8e66e1bf31e8227a05e2449445480bbab3d20b57a56
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 18, 2026.
Transparency log