Package: leetcode-alg
LeetCode-Py介绍LeetCode-Py仓库中包含2大内容. (持续更新中)包含大量leetcode(python)题目的解答(将会收集1k题以上, 目前处于开发中).算法库:leetcode-alg.LeetCode-Py的习题解答的风格是在最优复杂度的前提下, 写出最简洁的代码, 不做过多细节的优化. 旨在将最优雅的python代码放入answer/文件夹内.leetcode-alg是针对leetcode解题的数据结构和算法库, 其设计哲学是: 以通用性为核心, 并以最大可能进行性能优化.性能和功能answer/中time击败: (不使用trick)100%: 1, 11, 16, 18, 39, 42, 57, 72, 84, 85, 146, 167, 200, 300, 354, 416, 435, 518, 1143, 1349, 2096, 2171, 220395%: 2, 28, 40, 51, 52, 56, 102, 107, 112, 113, 124, 153, 204, 207, 210, 239, 307, 322, 454, 496, 503, 704, 875, 1044, o5185%: 4, 15, 19, 92, 208, 215, 876, 1584, o4060%:其他:已有的功能: (持续更新中)算法:array: unique, partition, partition2, merge, merge2, diff, quick_select, two_sumdp: LIS, LIS2, LCS, LCS2, LCS3, edit_distance, matrix_chain, matrix_chain2graph: dijkstra, dijkstra2, dijkstra3, kruskal, prim, prim2, topo_sort, Dinic, hungariangreed: merge_intervals, merge_intervals2knapsack: knapsack, knapsackV, knapsackC, knapsackCVlinkedlist: reverse_list, find_mid_node, find_last_kth_nodemath: is_prime, find_primesmonotone_deque: monotone_deque, monotone_deque2monotone_stack: monotone_stack, monotone_stack2, monotone_stack3, largest_rect, largest_rect2search: lower_bound, upper_bound, n_queensstring: build_nextval, kmptree: find_path, find_common_ancestor, inorder_traversal, level_order_traversalunimportant:array: reverse, euclidean_dist, manhattan_dist, prefix_sumbisect: bisect_left, bisect_right, binary_searchmath: gcd, lcm, fast_powrandom: randpermsort: quick_sort, merge_sort, heap_sort, heap_sort2数据结构:binary_indexed_tree: BinaryIndexedTree, BinaryIndexedTree2heap: Heap, Heap2linkedlist: LinkedListNode, LinkedListsegment_tree: SegmentTree, SegmentTree2sorted_list: SimpleSortedListstring_hasher: StringHasher, StringHasher2trie: TrieTreeNode, Trieunion_find: UnionFindunimportant:ordered_dict: OrderedDictLeetCode Tools:数据结构: ListNode, TreeNodetools: to_linkedlist, from_linkedlist, to_tree, from_tree, call_callable_listtodo算法:monotone_deque: next_ge_k_len, prev_le_k_lenmonotone_stack: next_ge_minstring_op: string_add, string_multree: bst_min, bst_maxunimportant:math: int2str, prime_factor, BigInteger数据结构:extension: BBST, HuffmanTree, RBTree安装和使用安装:# (推荐)将此仓库下载的本地, 进入setup.py所在目录, 输入以下命令pipinstall.# or 从pypi下载pipinstallleetcode-alg-U使用: 例子可以查看answer/fromleetcode_algimport*# if you want to import additional featuresfromleetcode_alg.extimport*索引数据结构线段树: 307Lazy:离散化: o51-(易混淆): 2021树状数组: 307变体:离散化: o51SortedList: o51哈希表: 1143, 2183, 416N数: 1, 15, 454链表:前向链表: 2, 19, 21, 23, 24, 25, 92, 876, 2181双向循环链表: OrderedDict单调栈/队列单调栈: 496, 503双向: 42, 84, 85单调队列: 239前缀树(Trie): 208-(易混淆): 14栈: 20堆: 23, 215, o40可动态修改的堆(Heap2): dijkstra, primUnionFind: kruskal, 200OrderedDict: 146(LRU)算法分治法:2路: 常见2路递归(merge sort, quick_sort, 树的dfs等), 23二分查找:自己设计cond:lower_bound: 4, 153, 875upper_bound:直接调用bisect: 704LIS: 300, 354, 435(非递减), 1143(LCS)滑动窗口: 3搜索:链:回溯: 17, 22, 39, 40, 51, 52树:回溯: 113dfs: 112, 124公共祖先: 2096递归模式dfs: 112bfs: 102, 107图:dfs: 200bfs: 200图算法:dijkstra: 2203(重边的处理)kruskal(稀疏图): 1584prim(稠密图): 1584拓扑排序: 207, 210dinic: 1349匈牙利算法: 1349DP(or memo-dfs):nums[i..j]: 5nums[..i]: 300, 435s[..i], s[..j]: 72, 1143双dp: 42, 2167背包: 39, 322, 416, 518双指针: 11, 42N数: 15, 16, 18, 167贪心: 11, 12, 42, 2037, 2038, 2182区间贪心: 56, 57, 435位运算: 2166字符串:字符串哈希: 28, 1044kmp: 28其他中心法: 双向单调栈, 5, 2171, 2203去重:N数: 15, 16, 18排序: 离散化, kruskal, 2171N数: 同双指针N数map有序化: 2021, 2165, 2170, 2183with贪心: 区间贪心, 2037-(非显式的sort): 12, 2182int溢出: 7, 8分类讨论:次大/小: 2170, 2182不以0开头: 7, 8, 2165其他: 线段树的query_range, 4, find_common_ancestor(2096)随机算法: 215, o40, quick_sort数学:gcd: 2183质数: 204日期:未分类暴力: 2180过于简单: 2022, 2164, 21696, 9, 13, 2043