{"id":16270691,"url":"https://github.com/jintao-huang/leetcode-py","last_synced_at":"2025-04-08T15:25:56.788Z","repository":{"id":97913919,"uuid":"607614454","full_name":"Jintao-Huang/LeetCode-Py","owner":"Jintao-Huang","description":"针对LeetCode解题开发的基于python的数据结构和算法库`leetcode-alg`","archived":false,"fork":false,"pushed_at":"2023-04-18T12:17:37.000Z","size":147,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-17T02:39:24.648Z","etag":null,"topics":["algorithm","data-structures","leetcode","leetcode-alg","leetcode-python","leetcode-solutions","python","python3"],"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/Jintao-Huang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-28T10:32:17.000Z","updated_at":"2023-03-06T13:27:29.000Z","dependencies_parsed_at":"2024-01-02T19:46:41.118Z","dependency_job_id":null,"html_url":"https://github.com/Jintao-Huang/LeetCode-Py","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jintao-Huang%2FLeetCode-Py","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jintao-Huang%2FLeetCode-Py/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jintao-Huang%2FLeetCode-Py/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jintao-Huang%2FLeetCode-Py/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Jintao-Huang","download_url":"https://codeload.github.com/Jintao-Huang/LeetCode-Py/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247869119,"owners_count":21009566,"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":["algorithm","data-structures","leetcode","leetcode-alg","leetcode-python","leetcode-solutions","python","python3"],"created_at":"2024-10-10T18:11:10.432Z","updated_at":"2025-04-08T15:25:56.756Z","avatar_url":"https://github.com/Jintao-Huang.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LeetCode-Py\n![Python Version](https://img.shields.io/badge/python-%E2%89%A53.8-5be.svg)\n[![PyPI Status](https://badge.fury.io/py/leetcode-alg.svg)](https://pypi.org/project/leetcode-alg/)\n[![License](https://img.shields.io/badge/License-MIT-yellowgreen.svg)](https://github.com/Jintao-Huang/LeetCode-Py/blob/main/LICENSE)\n\n\n## 介绍\n1. `LeetCode-Py`仓库中包含2大内容. (**持续更新中**)\n   1. 算法库: `leetcode-alg`. \n   2. 大量基于`leetcode-alg`的leetcode(python)题目的解答(将会收集**1k题**以上, 目前处于开发中). \n2. `LeetCode-Py`的**习题解答的风格**是在最优复杂度的前提下, 写出最简洁的代码, 不做过多细节的优化. 旨在将**最优雅**的python代码放入`answer/`文件夹内. \n3. `leetcode-alg`是针对leetcode解题的数据结构和算法库, 其**设计哲学**是: 以通用性为核心, 并以最大可能进行性能优化. \n\n\n## 性能和功能\n1. 性能: `answer/`中**time击败**: \n   1. 100%: 1, 11, 16, 18, 39, 42, 46, 57, 72, 77, 78, 84, 85, 146, 167, 200, 215, 300, 354, 416, 435, 518, 1143, 1349, 2096, 2171, 2203\n   2. 95%: 2, 22, 28, 31, 40, 47, 51, 52, 56, 90, 102, 107, 112, 113, 124, 153, 204, 207, 210, 239, 307, 322, 454, 496, 503, 704, 875, 1044, o51\n   3. 85%: 4, 15, 19, 92, 208, 876, 1584, o40\n   4. 60%: \n   5. 其他: \n2. 已有的功能: (持续更新中)\n   1. 算法: \n      1. array: unique, partition, partition2, merge, merge2, diff, quick_select, two_sum, reverse, next_permutation, subsets, subsets2\n      2. dp: LIS, LIS2, LCS, LCS2, LCS3, edit_distance, matrix_chain, matrix_chain2\n      3. heapq: nlargest_, nsmallest_, nlargest2, nsmallest2, merge_heapq_\n      4. graph: dijkstra, dijkstra2, dijkstra3, kruskal, prim, prim2, topo_sort, Dinic, hungarian\n      5. greed: merge_intervals, merge_intervals2\n      6. knapsack: knapsack, knapsackV, knapsackC, knapsackCV\n      7. linkedlist: reverse_list, find_mid_node, find_last_kth_node\n      8. math: is_prime, find_primes\n      9. monotone_deque: monotone_deque\n      10. monotone_stack: monotone_stack, monotone_stack2, monotone_stack3, largest_rect, largest_rect2\n      11. search: lower_bound, upper_bound, n_queens\n      12. string: build_nextval, kmp\n      13. tree: find_path, find_common_ancestor, preorder_traversal, preorder_traversal2, inorder_traversal, inorder_traversal2, postorder_traversal, postorder_traversal2, level_order_traversal\n      14. unimportant: \n          1. array: euclidean_dist, manhattan_dist\n          2. bisect: bisect_left_, bisect_right_, binary_search\n          3. itertools: accumulate_, product_, permutations_, permutations2, combinations_, combinations2, combinations_with_replacement_, combinations_with_replacement2\n          4. math: gcd_, lcm_, fast_pow\n          5. random: randperm\n          6. sort: quick_sort, merge_sort, heap_sort, heap_sort2\n   2. 数据结构:\n      1. binary_indexed_tree: BinaryIndexedTree, BinaryIndexedTree2\n      2. heap: Heap, Heap2\n      3. linkedlist: LinkedListNode, LinkedList\n      4. segment_tree: SegmentTree, SegmentTree2\n      5. sorted_list: SimpleSortedList\n      6. string_hasher: StringHasher\n      7. trie: TrieTreeNode, Trie\n      8. union_find: UnionFind\n      9. unimportant: \n         1. ordered_dict: OrderedDict_\n   3. LeetCode Tools:\n      1. 数据结构: ListNode, TreeNode\n      2. tools: to_linkedlist, from_linkedlist, to_tree, from_tree, call_callable_list\n3. todo\n   1. 算法: \n      1. monotone_deque: next_ge_k_len, prev_le_k_len\n      2. monotone_stack: next_ge_min\n      3. string_op: string_add, string_mul\n      4. tree: bst_min, bst_max\n      5. unimportant: \n         1. math: int2str, prime_factor, BigInteger\n   2. 数据结构: \n      1. sorted_list: SortedList\n      2. extension: BBST, HuffmanTree, RBTree, SkipList\n\n\n\n\n## 安装和使用\n1. 安装: \n    ```bash\n    # (推荐)将此仓库下载的本地, 进入setup.py所在目录, 输入以下命令\n    pip install .\n    # or 从pypi下载\n    pip install leetcode-alg -U\n    ```\n    \n2. 使用: 例子可以查看`answer/`\n   ```python\n   from leetcode_alg import *\n   ```\n\n\n\n## 索引\n### 数据结构\n1. 线段树: 307\n   1. Lazy: \n   2. 离散化: o51\n   3. -(易混淆): 2021\n2. 树状数组: 307\n   1. 变体: \n   2. 离散化: o51\n3. SortedList: o51\n4. 哈希表: 1143, 2183, 416\n   1. N数: 1, 15, 454\n5. 链表: \n   1. 前向链表: 2, 19, 21, 23, 24, 25, 92, 876, 2181\n   2. 双向循环链表: OrderedDict, 146(LRU)\n6. 单调栈/队列\n   1. 单调栈: 496, 503\n      1. 双向: 42, 84, 85\n   2. 单调队列: 239\n7. 前缀树(Trie): 208\n   1. -(易混淆): 14\n8. 栈: 20\n9. 堆: 23, 215, o40\n   1. 可动态修改的堆(Heap2): dijkstra, prim\n10. UnionFind: kruskal, 200\n\n\n\n\n### 算法\n1. 分治法: \n   1. 2路: 常见2路递归(merge sort, quick_sort, 树的dfs等), 23(相关题: n路归并)\n2. 二分查找: \n   1. 自己设计cond: \n      1. lower_bound: 4, 153, 875\n      2. upper_bound: \n   2. 直接调用bisect: 704\n      1. LIS: 300, 354, 435(非递减), 1143(LCS)\n3. 滑动窗口: 3\n4. 搜索:\n   1. 链: \n      1. 回溯: 17, 22, 37, 51, 52\n         1. 子集: 39, 40, 78, 90\n         2. 组合: 77\n         3. 排列: 31(相关题), 46, 47, 679\n   2. 树: \n      1. 回溯: 113\n      2. dfs: 112, 124\n         1. 公共祖先: 2096\n         2. 迭代式dfs: 112\n      3. bfs: 102, 107\n   3. 图: \n      1. dfs: 200\n      2. bfs: 200\n5. 图算法: \n   1. dijkstra: 2203(重边的处理)\n   2. kruskal(稀疏图): 1584\n   3. prim(稠密图): 1584\n   4. 拓扑排序: 207, 210\n   5. dinic: 1349\n   6. 匈牙利算法: 1349\n6. DP(or memo-dfs): \n   1. nums\\[i..j\\]: 5\n   2. nums\\[..i\\]: 300, 435\n   3. s\\[..i\\], s\\[..j\\]: 72, 1143\n   4. 双dp: 42, 2167\n   5. 背包: 39, 322, 416, 518\n7. 双指针: 11, 42\n   1. N数: 15, 16, 18, 167\n8. 贪心: 11, 12, 42, 2037, 2038, 2182\n   1. 区间贪心: 56, 57, 435\n9. 位运算: 2166\n10. 字符串: \n    1. 字符串哈希: 28, 1044\n    2. kmp: 28\n\n\n\n#### 其他 \n1. 中心法: 双向单调栈, 5, 2171, 2203\n2. 去重: 40, 47, 90\n   1. N数: 15, 16, 18\n3. 排序: 去重, 离散化, kruskal, 2171\n   1. map有序化: 2021, 2165, 2170, 2183\n   2. with贪心: 区间贪心, 2037\n      1. -(非显式的sort): 12, 2182\n   3. 桶排序: 215\n4. int溢出: 7, 8\n5. 分类讨论: \n   1. 次大/小: 2170, 2182\n      1. 不以0开头: 7, 8, 2165\n   2. 其他: 线段树的query_range, 4, find_common_ancestor(2096)\n6. 随机算法: 215, o40, quick_sort\n7. 数学: \n   1. gcd: 2183\n   2. 质数: 204\n8. 日期: \n\n\n\n\n### 未分类 \n1. 暴力: 2180\n2. 过于简单: 2022, 2164, 2169\n3. 6, 9, 13, 2043\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjintao-huang%2Fleetcode-py","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjintao-huang%2Fleetcode-py","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjintao-huang%2Fleetcode-py/lists"}