Skip to content

Repository files navigation

LeetCode Practice

用 Python 練習解題,並用 pytest 與 Hypothesis 驗證結果。目前收錄 44 題:42 題 Easy、2 題 Medium,每題都有對應測試。

開始練習

需要 Python 3.12 以上與 Poetry。在專案根目錄執行:

poetry install
poetry run pytest -q

只跑一組或一題:

poetry run pytest tests/tree -q
poetry run pytest tests/array/test_lc_026_remove_duplicates_from_sorted_array.py -q

VS Code 的偵錯設定放在 .vscode/launch.jsonargs 可指定測試檔案,或使用 檔案路徑::測試函式名稱 選擇案例。

專案結構

src/                 解法,依題目主體分類
  array/
  string/
  linkedlist/
  stack/
  queue/
  tree/
tests/               與 src 使用相同 Group、題號及檔名
  tree/utils/        樹的測資建構工具
  linkedlist/utils/  串列、環與交集的測資建構工具
docs/
  patterns/          依解題思路編排的教學
  testing.md         測試案例、性質與狀態機
  problem-index.md   全部題目的 source、test、筆記連結

例如 src/tree/lc_094_binary_tree_inorder_traversal.py 對應 tests/tree/test_lc_094_binary_tree_inorder_traversal.py。樹的走訪即使用 stack 實作,仍放在 tree;詳見 分類規則

閱讀筆記

筆記描述目前執行中的解法。註解中的替代版本與待補案例會另行說明;複雜度也計入 Python 切片、暫存陣列與遞迴堆疊。

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages