LeetCode
海晨威
Growth is a song
展开
-
LeetCode之排列[ Permutations ] 组合[ Combinations ]与实现[ Python ]
leetcode中有两道经典的题目,求一个数组的排列和组合,都可以用深度优先递归搜索的方式来求解,让我们一起来look look。排列[ Permutations ]题:Given a collection of distinct integers, return all possible permutations.Example:Input: [1,2,3]Output:[ [1...原创 2019-05-28 21:32:16 · 1329 阅读 · 0 评论 -
LeetCode之Word Break-动态规划python解法
Word Break LeetCode 139Given a non-empty string s and a dictionary wordDict containing a list of non-emptywords, determine if s can be segmented into a space-separated sequence of one or more dictio...原创 2019-06-02 11:50:25 · 703 阅读 · 0 评论 -
LeetCode之Reverse Linked List II-python递归解法
题:Reverse a linked list from position m to n. Do it in one-pass.Note: 1 ≤ m ≤ n ≤ length of list.Example:Input: 1->2->3->4->5->NULL, m = 2, n = 4Output: 1->4->3->2->5-&...原创 2019-06-15 11:31:06 · 678 阅读 · 0 评论 -
LeetCode之Unique Binary Search Trees I and II python解法
LeetCode之Unique Binary Search Trees I and II python解法题:Unique Binary Search Trees IGiven n, how many structurally unique BST’s (binary search trees) that store values 1 … n?Example:Input: 3Outpu...原创 2019-07-27 14:43:29 · 368 阅读 · 0 评论 -
快排的两种partition函数
partition函数就是快排的关键部分,作用是将数组划分成两部分,左边小于基数,右边大于基数但实际上它也不仅仅用于快排,在求top(K)问题中也常常会用到。下面介绍两种partition函数,他们都是双指针的方法,但具体会有差异:函数一:头尾指针向中间夹def partition(array,left,right): baseNumber = array[left] # 基数的位...原创 2019-08-31 19:43:12 · 2679 阅读 · 0 评论 -
链表的快排和归并排序
链表快排对一个单链表用快排的方式排序快排的关键在于partition函数,因为单链表是不能倒序遍历的,因此不能通过头尾双指针向内夹的partition函数,而是用都是从头开始的双指针方式,具体的两种partition函数可以参考:快排的两种partition函数这里链表快排和数组快排partition函数中关键的不同点在于:partition函数中遍历结束的方式,和递归结束的方式# 链表快...原创 2019-08-31 19:45:27 · 852 阅读 · 0 评论