Java 0 ms 4 lines extremely simple solution


  • 0
        public void sortColors(int[] nums) {
            int cs[] = new int[3], k = 0;
            for (int n : nums) cs[n]++;
            for (int i = 0; i < 3; i++)
                for (int j = 0; j < cs[i]; j++) nums[k++] = i;
        } 
    

Log in to reply
 

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