LeetCode-Alg: 针对LeetCode解题开发的基于python的数据结构和算法库
github: https://github.com/Jintao-Huang/LeetCode-Py
经过一个月的断断续续的开发, 终于把这个库的第一版开发出来啦. `leetcode_alg==0.1.0`
介绍
LeetCode-Py仓库只要包含两大内容: 算法库leetcode_alg, 以及基于leetcode_alg的大量leetcode题目的python解答(将会收集1k题以上, 持续更新中)
LeetCode-Py的习题解答风格: 最优复杂度, 最简洁最优雅的代码(尽量避免过多的细节优化), 时间性能上保证打败85%的代码.
leetcode_alg库的设计哲学: 以通用性为核心, 并以最大可能进行性能优化.
性能和功能
answer/中时间击败: (持续更新中)
100%: 1, 16, 18, 39, 42, 72, 84, 146, 167, 200, 300, 354, 416, 518, 1143, 1349, 2096, 2203
95%: 2, 11, 28, 40, 51, 52, 102, 107, 112, 113, 124, 153, 204, 207, 210, 322, 454, 496, 503, 704, 875, 1044, o51
85%: 4, 15, 19, 85, 92, 208, 215, 307, 876, 1584, o40
其他:
leetcode_alg已有的功能: (持续更新中)
算法:
array: unique, partition, partition2, merge, merge2, diff, quick_select, two_sum
dp: LIS, LIS2, LCS, LCS2, edit_distance, matrix_chain, matrix_chain2
graph: dijkstra, dijkstra2, dijkstra3, kruskal, prim, prim2, topo_sort, Dinic, hungarian
greed: merge_intervals, merge_intervals2
knapsack: knapsack, knapsackV, knapsack_C, knapsackV_C
linkedlist: reverse_list, find_mid_node, find_last_kth_node
math: is_prime, find_primes
monotone_deque: monotone_deque, monotone_deque2
monotone_stack: monotone_stack, monotone_stack2, monotone_stack3, largest_rect, largest_rect2
search: lower_bound, upper_bound, n_queens
string: build_nextval, kmp
tree: find_path, find_common_ancestor, inorder_traversal, level_order_traversal
unimportant: reverse, euclidean_dist, manhattan_dist, prefix_sum, bisect_left, bisect_right, binary_search, gcd, lcm, fast_pow, randperm, quick_sort, merge_sort, heap_sort, heap_sort2
数据结构:
binary_indexed_tree: BinaryIndexedTree, BinaryIndexedTree2
heap: Heap, Heap2
linkedlist: LinkedListNode, LinkedList
segment_tree: SegmentTree, SegmentTree2
sorted_list: SimpleSortedList
string_hasher: StringHasher, StringHasher2
trie: TrieTreeNode, Trie
union_find: UnionFind
unimportant: OrderedDict
LeetCode Tools:
数据结构: ListNode, TreeNode
tools: to_linkedlist, from_linkedlist, to_tree, from_tree, call_callable_list
安装和使用
安装: `pip install leetcode-alg` (from pypi)
使用: 可以查看answer/