C# Solution


  • 0
    P
            public static void SortColors(int[] nums)
            {
                List<int> li = new List<int>();
                for (int i = 0; i < nums.Length; i++)
                {
                    if (nums[i] == 0)
                        li.Insert(0, 0);
                    if (nums[i] == 1)
                    {
                        if (li.Count > i)
                            li[i] = 1;
                        else
                            li.Add(1);
                    }
                    if (nums[i] == 2)
                        li.Add(2);
                }
                nums = li.ToArray<int>();
            }

Log in to reply
 

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