My swift solution


  • 0
    C
    class Solution {
        func moveZeroes(inout nums: [Int]) 
        {
            var cur_zero_index: Int = -1
            var index: Int = 0
            
            for num in nums
            {
                if( num == 0 && cur_zero_index == -1 )
                {
                    cur_zero_index = index
                }
                else if( num != 0 && cur_zero_index != -1 )
                {
                    nums[ cur_zero_index ] = nums[ index ]
                    nums[ index ] = 0
                    
                    cur_zero_index++
                }
                
                index++
            }
            
        }
    }

Log in to reply
 

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