C# bubblesort-esque solution


  • 0
    B
    public class Solution {
        public void MoveZeroes(int[] nums) {
        	bool sorted = false;
        	
        	while (!sorted)
        	{
        	    sorted = true;
        		
        	    for (int i = 0; i < nums.Length-1; i++)
                {
                	if (nums[i] == 0 && nums[i+1] != 0)
                	{
                		sorted = false;
                		nums[i] = nums[i+1];
                		nums[i+1] = 0;
                	}
                }   
        	}
        }
    }
    

Log in to reply
 

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