My Simple Swift Solution


  • 0
    Y
    func moveZeroes(_ nums: inout [Int]) {
            var j = 0
            for i in 0..<nums.count{
                if nums[i] != 0{
                    nums[j] = nums[i]
                    j += 1
                }
            }
    
            while j < nums.count {
                nums[j] = 0
                j += 1
            }
    }

Log in to reply
 

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