LoginSignup
0
0

More than 5 years have passed since last update.

Leetcode #83: Remove Duplicates from Sorted List

Posted at
func deleteDuplicates(_ head: ListNode?) -> ListNode? {
    var pre = head
    var next = pre?.next
    while next != nil {
        if pre!.val == next!.val {
            pre?.next = next?.next
            next = pre?.next
        } else {
            pre = next
            next = next?.next
        }
    }
    return head
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0