Quick Select 快速选择
October 16, 2022
1283
开篇废话
最近有重要面试,时间真的很紧张啊!不会的还有好多,只能逐个快速击破了!QwQ
流程
- Choose a random pivot.
- Use a partition algorithm to place the pivot into its perfect position pos in the sorted array, move smaller elements to the left of pivot, and larger or equal ones - to the right.
- Compare pos and N - k to choose the side of array to proceed recursively.
模版
自用简易模版
1 |
|
练习
- 215. Kth Largest Element in an Array 非常直接
- 973. K Closest Points to Origin 直接+1
- 347. Top K Frequent Elements 加了一个map
- 1985. Find the Kth Largest Integer in the Array 变成String比较,而且数值更大了
- 324. Wiggle Sort II 太难了,放弃了