✔️ 100% Fastest Swift Solution, time: O(n), space: O(1).
\n/**\n * Definition for singly-linked list.\n * public class ListNode {\n *     public var val: Int\n *     public var next: ListNode?\n *     public init() { 
```\n/**\n * Definition for singly-linked list.\n * public class ListNode {\n *     public var val: Int\n *     public var next: ListNode?\n *     public init() { self.val = 0; self.next = nil; }\n *     public init(_ val: Int) { self.val = val; self.next = nil; }\n *     public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }\n * }\n */\nclass Solution {\n    // - Complexity:\n    //   - time: O(n), where n is the number of nodes in the linked list.\n    //   - space: O(1), only constant space is used.\n\n    func deleteDuplicates(_ head: ListNode?) -> ListNode? {\n        let dummy: ListNode? = ListNode(-1)\n        dummy?.next = head\n\n        var curr = dummy\n        while let nextVal = curr?.next?.val, let nextNextVal = curr?.next?.next?.val {\n            if nextVal == nextNextVal {\n                let duplicate = nextVal\n                while curr?.next != nil, curr?.next?.val == duplicate {\n                    curr?.next = curr?.next?.next\n                }\n            } else {\n                curr = curr?.next\n            }\n        }\n\n        return dummy?.next\n    }\n\n}\n```\n\nLet me know in comments if you have any doubts. I will be happy to answer.\n\nPlease upvote if you found the solution useful.
['Swift']