Getting last two testcases incorrect with C# Solution passed rest testcases.


  • 0
    P
                             public static void MoveZeroes(int[] nums)
                            {
                                         var temp = 0;
                                         for (var x = 0; x < nums.Length; x++)
                                         {
                                                if (nums[x] == 0)
                                        {
    
                                                for (var y = x + 1; y <= nums.Length - 1; y++)
                                               {
                                                       temp = nums[y - 1];
                                                       nums[y - 1] = nums[y];
                                                       nums[y] = temp;
                                               }
                                         }
                                              else if (x != 0 && nums[x - 1] == 0)
                                          {
    
                    for (var y = x; y <= nums.Length - 1; y++)
                    {
                        temp = nums[y - 1];
                        nums[y - 1] = nums[y];
                        nums[y] = temp;
    
    
                    }
                }
            }
                                            for (int z=0;z<nums.Length;z++)
                                               {
                                                      Console.Write(+nums[z]+" "); 
                                                  }
                                           }

Log in to reply
 

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