Partition Array
Given an arraynums
of integers and an intk
, partition the array (i.e move the elements in "nums") such that:
Return the partitioning index, i.e the first indexi_nums[_i] >=k.
Notice
You should do really partition in array_nums_instead of just counting the numbers of integers smaller than k.
If all elements innums_are smaller than_k, then returnnums.length
Example
If nums =[3,2,2,1]
andk=2
, a valid answer is1
.
分析
对撞型指针,只需要把数移到K左右两边,无需排序,所以没有递归。
答案:
Last updated