Short Swift solution


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

Log in to reply
 

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