simple java solution


  • 0
    S

    public class Solution {
    public static void sortColors(int[] nums) {
    int n1=0,n2=0,n3=0;

        for(int i=0;i<nums.length;i++)
        
        {
            
            
            
            if(nums[i]==0)n1++;
            
             if(nums[i]==1)n2++;
              if(nums[i]==2)n3++;
            
        }
        
        for(int i=0;i<n1;i++)nums[i]=0;
                for(int j=0;j<n2;j++)nums[n1+j]=1;
    
        for(int k=0;k<n3;k++)nums[n2+n1+k]=2;
    
        
    
    
    	
    
    
    }
    

    }


Log in to reply
 

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