283. Move Zeroes | C# | Fast
Runtime: 231 ms, faster than 88.74% of C# online submissions for Move Zeroes.
Memory Usage: 44.6 MB, less than 9.44% of C# online submissions for Move Zeroes.
public class Solution {
    public void MoveZeroes(int[] nums) {
        int nonZeroIdx=0;
        int Idx=0;
    
        
        if(nums.Length <=1){
            return;
        } 
        
        
        while(Idx < nums.Length){
            if(nums[Idx]==0){
                Idx++;
            }
            else
            {
                nums[nonZeroIdx]=nums[Idx];
                if (Idx!=nonZeroIdx){
                    nums[Idx]=0;
                }
                Idx++;
                nonZeroIdx++;
            }
        }
    }
}
Comments (0)