My Swift Solution


  • 0
    J
    func deleteDuplicates(head: ListNode?) -> ListNode? {
            var currentNode = head
            while currentNode?.next != nil {
                if currentNode!.val == currentNode!.next!.val {
                    currentNode!.next = currentNode!.next!.next
                } else {
                    currentNode = currentNode!.next
                }
            }
    
            return head
        }

Log in to reply
 

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