4ms c++


  • 0
    B
    class Solution {
    public:
        void sortColors(vector<int>& nums) {
            int zero=-1,one=-1,two=-1;
            int n=nums.size();
            for(int i=0;i<n;i++)
            {
                if (nums[i]==0)
                {
                    nums[++two]=2;
                    nums[++one]=1;
                    nums[++zero]=0;
                    continue;
                }
                if (nums[i]==1)
                {
                    nums[++two]=2;
                    nums[++one]=1;
                    continue;
                }
                nums[++two]=2;
            }
        }
    };
    

Log in to reply
 

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