lintcode5 - Kth Largest Element - medium
基础知识补充 if: 就是一个判断的,如果满足后面的条件就继续运行if语句里面的东西的,要是不满足就跳出来,执行else语句或执行下面的语句的 。 while: 就是循环语句的,当满足while里面的条件时,就会执行里面的循环体的,直到条件不满足为止。 左右都取等号 避免 极端情况 Find K-th largest element in an array. Example In array [9,3,2,4,8], the 3rd largest element is 4. In array [1,2,3,4,5], the 1st largest element is 5, 2nd largest element is 4, 3rd largest element is 3 and etc. Challenge O(n) time, O(1) extra memory. Notice You can swap elements in the array Quick select. O(n)。一轮O(n)操作后把原问题化解为规模仅一半的问题(只接着搜其中一半了) 实现:指针+递归。指针分为双指针和三指针两种写法,递归分为改变k和不改变k的写法。 三指针:中间扫描,大扔左,小扔右,最后l左边的肯定全大的,r右边肯定全小的,lr加上中间的是==的。具体非对称写法还是“从左开始扫