邏輯Logic iOS 底層大師班2期班
? private int partition(int[] nums, int start, int end) {
? ? ? ?int pivotValue = nums[end];
? ? ? ?int j = start - 1;
? ? ? ?for (int i = start; i < end; i++) {
? ? ? ? ? ?if (nums[i] <= pivotValue) {
? ? ? ? ? ? ? ?j++;
? ? ? ? ? ? ? ?if (i != j) {
? ? ? ? ? ? ? ? ? ?swap(nums, i, j);
? ? ? ? ? ? ? ?}
? ? ? ? ? ?}
? ? ? ?}
? ? ? ?swap(nums, j + 1, end);
? ? ? ?return j + 1;
? ?}
標簽: