See other problems and solutions here https://jinblack.com/leetcode-swift/

class Solution {
    func deleteDuplicates(_ head: ListNode?) -> ListNode? {
        var node = head
        while node != nil {
            if node?.val == node?.next?.val {
                node?.next = node?.next?.next
            } else {
                node = node?.next
            }
        }
        return head
    }
}

Runtime: 32 ms, faster than 93.08% of Swift online submissions for Remove Duplicates from Sorted List.
Memory Usage: 18.9 MB, less than 41.18% of Swift online submissions for Remove Duplicates from Sorted List.