Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

sort 0 1 2 leetcode

/* Dutch National flag algorithm  --  IN-PLACE */
        int low = 0 ,  mid = 0  , high = nums.size()-1 ; 
        while (mid <= high) {
            if (nums[mid] == 0) {
                swap(nums[low] , nums[mid]) ; 
                mid++ ; low++ ; 
            }
            else if (nums[mid] == 1) {
                mid++ ;
            }
            else {
                swap(nums[mid] , nums[high]) ; 
                high-- ; 
            }
        }
 
PREVIOUS NEXT
Tagged: #sort #leetcode
ADD COMMENT
Topic
Name
9+9 =