My Simple Swift Solution (15ms)


  • 0
    Y
    func removeElement(_ nums: inout [Int], _ val: Int) -> Int {
        var j = 0
        for i in 0..<nums.count{
            if nums[i] != val{
                nums[j] = nums[i]
                j+=1
            }
        }
        return j
    }

Log in to reply
 

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