![](https://img-blog.csdnimg.cn/20201014180756923.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
排序
Alwaysion
more persistent for nothing
个人qq:790693499,欢迎来交流
展开
-
【力扣剑指 Offer 49. 丑数、力扣264】dp+最小堆(python3)
题目描述 https://leetcode-cn.com/problems/chou-shu-lcof/ 思路题解 https://leetcode-cn.com/problems/chou-shu-lcof/solution/chou-shu-by-leetcode-solution-0e5i/ dp class Solution: def nthUglyNumber(self, n: int) -> int: dp = [0] * (n + 1) dp[1]原创 2021-07-28 14:33:32 · 81 阅读 · 0 评论 -
旋转数组总结(力扣33 搜索旋转排序数组、81 搜索旋转排序数组 II)
33 搜索旋转排序数组 81 搜索旋转排序数组 II原创 2021-07-28 10:12:21 · 87 阅读 · 0 评论 -
【力扣剑指 Offer 40. 最小的k个数】TOP-K的经典解法:基于快排的数组划分和堆排序(Python3)
题目描述 https://leetcode-cn.com/problems/zui-xiao-de-kge-shu-lcof/ 思路题解 基于快排的数组划分 https://leetcode-cn.com/problems/zui-xiao-de-kge-shu-lcof/solution/jian-zhi-offer-40-zui-xiao-de-k-ge-shu-j-9yze/链接第二个方法 class Solution: def getLeastNumbers(self, arr: List原创 2021-07-06 10:58:32 · 90 阅读 · 0 评论 -
【力扣-剑指 Offer 11. 旋转数组的最小数字+33. 搜索旋转排序数组】二分(python3)
题目描述 https://leetcode-cn.com/problems/xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof/ 思路题解 其实可以直接求min,但是本题目的重点在于利用旋转数组的特性来降低时间复杂度。 大佬的题解:https://leetcode-cn.com/problems/xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof/solution/mian-shi-ti-11-xuan-zhuan-shu-zu-de-zui-原创 2021-06-30 16:27:10 · 77 阅读 · 0 评论 -
【力扣215-数组中的第K个最大元素】两种解法:普通法+随机pivot快排(python3+golang)
目录题目描述思路题解方法一:普通法方法二:随机pivot快排 题目描述 https://leetcode-cn.com/problems/kth-largest-element-in-an-array 思路题解 方法一:普通法 把每次的最大值求出来,删除掉,直到第k次,输出最大值 class Solution: def findKthLargest(self, nums: List[int], k: int) -> int: if not nums:return -1原创 2020-12-01 17:38:06 · 659 阅读 · 0 评论 -
【力扣56-合并区间】排序+模拟(python3)
目录题目描述思路代码 题目描述 https://leetcode-cn.com/problems/merge-intervals/submissions/ 思路代码 先对输入数据进行sort排序,设置start和end的初始值为intervals[0]的左右元素,进行遍历,更新start和end的值,加入到ans中,最后返回ans。 class Solution: def merge(self, intervals: List[List[int]]) -> List[List[int]]:原创 2020-11-23 16:26:49 · 161 阅读 · 1 评论 -
【力扣面试题16.16-部分排序】分类判断+剪枝(python3)
目录题目描述思路题解 题目描述 https://leetcode-cn.com/problems/sub-sort-lcci/ 思路题解 设置一个low,一个high代表最后返回的数组切片的索引。该切片满足如下条件: 1.[low,high]内最小值>=array[low-1],且array[0,low-1]有序 2.[low,high]内最大值>=array[high+1],且array[high+1,len(array)-0]有序 于是先定位切片长度最小的[low,high],再求出切片内部原创 2020-11-23 14:37:04 · 157 阅读 · 1 评论