A Swift Solution, O(n)


  • 0
    L
    func removeElement(inout nums: [Int], _ val: Int) -> Int {
        guard nums.count > 0 else { return 0 }
        nums = nums.filter { $0 != val }
        return nums.count
    }
    
    

Log in to reply
 

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