c++


  • 0
    class Solution {
    public:
        void sortColors(vector<int>& nums) 
        {
         int size = nums.size()-1;
         int start=0,mid=0,end=size;
         int mid_val = 1;
         
         while(mid <= end)
         {
             if(nums[mid] < mid_val)
               std::swap(nums[mid++],nums[start++]);
             else if(nums[mid] > mid_val)
                 std::swap(nums[mid],nums[end--]);
             else
                 mid++;
        }
        
        }
    };
    

Log in to reply
 

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