Given an array nums of integers and an int k, partition the array (i.e move the elements in "nums") such that:
All elements < k are moved to the left
All elements >= k are moved to the right
Return the partitioning index, i.e the first index i nums[i] >= k.
代码
Approach #1 单指针索引交换
publicclassSolution {publicintpartitionArray(int[] nums,int k) {int right =0;int size =nums.length;for (int i =0; i < size; i++) {if (nums[i] < k) {if (i != right) {int temp = nums[i]; nums[i] = nums[right]; nums[right] = temp; }++right; } }return right; }}