three routes quick sort


  • 0
    J

    public static void sortColors(int[] nums) {
    int index = 0;
    int l = -1;

        int r = nums.length;
        while (index<r){
            if(nums[index]==0){
                l++;
                int temp = nums[index];
                nums[index] = nums[l];
                nums[l] = temp;
                index++;
            }else if(nums[index]==2){
                r--;
                int temp = nums[r];
                nums[r] = nums[index];
                nums[index] = temp;
    
            }else{
                index++;
            }
    
        }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.