My Java 6-line solution applied to more 3 colors

  • 0

    Isn't this problem easy?

    public class Solution {
        public void sortColors(int[] nums) {
            for(int i=0; i<nums.length-1; i++){
                for(int j=i+1;j<nums.length; j++){
                        int temp = nums[i];
                        nums[i] = nums[j];
                        nums[j] = temp;

Log in to reply

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