Remove Duplicates from Sorted List II
Example
Solution
"""
Definition of ListNode
class ListNode(object):
def __init__(self, val, next=None):
self.val = val
self.next = next
"""
class Solution:
"""
@param head: A ListNode
@return: A ListNode
"""
def deleteDuplicates(self, head):
if head == None or head.next == None:
return head
dummy = ListNode(0)
dummy.next = head
head = dummy
while head.next and head.next.next:
if head.next.val == head.next.next.val:
val = head.next.val
while head.next and head.next.val == val:
head.next = head.next.next
else:
head = head.next
return dummy.nextLast updated