Why your testing case get me a wrong output?


  • 0
    D

    List<int> list = new List<int>();
    int[] result = new int[nums.Count()];
    for (int i = 0; i < nums.Count(); i++)
    {
    if (nums[i] == 0) list.Add(0);
    }
    for (int i = 0; i < nums.Count(); i++)
    {
    if (nums[i] == 1) list.Add(1);
    }
    for (int i = 0; i < nums.Count(); i++)
    {
    if (nums[i] == 2) list.Add(2);
    }
    result = list.ToArray();
    nums = result;
    for (int i = 0; i < nums.Count(); i++)
    {
    System.Console.Write(nums[i]+" ");
    }

    //////////////////////////////
    Input:
    [1,0]
    Output:
    [1,0]
    Expected:
    [0,1]

    print out: 0 1


Log in to reply
 

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