
quick select
文章平均质量分 85
flyatcmu
这个作者很懒,什么都没留下…
展开
-
Find the Kth Largest Integer in the Array
You are given an array of stringsnumsand an integerk. Each string innumsrepresents an integer without leading zeros.Returnthe string that represents thekthlargest integerinnums.Note: Duplicate numbers should be counted distinctly. For example...原创 2022-01-21 07:39:49 · 157 阅读 · 0 评论 -
K Closest Points to Origin
Given somepointsand anoriginpoint in two-dimensional space, findkpoints which are nearest to theorigin.Return these points sorted by distance, if they are same in distance, sorted by the x-axi...原创 2019-11-15 14:42:47 · 276 阅读 · 0 评论 -
Sorting (Merge Sort, Rainball Sort, quick select) 总结
Merge k Sorted Lists(这题是用PQ,或者merge sort都可以做,关于第K大的问题,参考: PriorityQueue 第K大问题总结)Sort an Array ( 重点掌握merge sort和quick sort,因为两者可以演变为很多其他的算法,divide conquer, quick select)Merge IntervalsSort ColorsSort ListConvert Sorted Array to Binary Searc...原创 2020-07-05 07:08:51 · 464 阅读 · 0 评论 -
Find Kth题目类型总结 (quick Select 类型总结)
找第k大或者第k小的题型,也是经常面试考,这里做个总结;首先quick select算法的模板要倒背如流,这个是通过quick sort里面提炼得到的算法;两个while一个if,condition相同;后面再递归Kth Smallest Numbers in Unsorted Array找到一个无序数组中第K小的数Example样例 1:输入: [3, 4, 1, 2,...原创 2020-01-07 15:01:55 · 2113 阅读 · 0 评论 -
Kth Largest Element II
Find K-th largest element in an array. and N is much larger than k. Note that it is the kth largest element in the sorted order, not the kth distinct element.ExampleExample 1:Input:[9,3,2,4,8],...原创 2020-01-02 13:27:54 · 259 阅读 · 0 评论 -
Sort Colors II
Given an array ofnobjects withkdifferent colors (numbered from 1 to k), sort them so that objects of the same color are adjacent, with the colors in the order 1, 2, ... k.ExampleExample1Inp...原创 2019-11-08 12:52:42 · 242 阅读 · 0 评论 -
Kth Largest Element in an Array
Find K-th largest element in an array.ExampleExample 1:Input:n = 1, nums = [1,3,4,2]Output:4Example 2:Input:n = 3, nums = [9,3,2,4,8]Output:4ChallengeO(n) time, O(1) extra memo...原创 2016-08-24 13:16:00 · 497 阅读 · 0 评论 -
Sort an Array
Given an integer array, sort it in ascending order. Use selection sort, bubble sort, insertion sort or any O(n2) algorithm.ExampleExample 1: Input: [3, 2, 1, 4, 5] Output: [1, 2, 3, 4, 5] E...原创 2019-12-27 13:36:29 · 245 阅读 · 0 评论 -
Nuts bolts problem
Given a set ofnnuts of different sizes andnbolts of different sizes. There is a one-one mapping between nuts and bolts.Comparison of a nut to another nut or a bolt to another bolt isnot allowed...原创 2019-12-17 12:17:37 · 696 阅读 · 0 评论 -
Kth Smallest Numbers in Unsorted Array
Find the kth smallest number in an unsorted integer array.ExampleExample 1:Input: [3, 4, 1, 2, 5], k = 3Output: 3Example 2:Input: [1, 1, 1], k = 2Output: 1ChallengeAn O(nlogn) algo...原创 2019-11-24 14:56:40 · 387 阅读 · 0 评论