Leetcode 83. Remove Duplicates from Sorted List

# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution:
    def deleteDuplicates(self, head: ListNode) -> ListNode:
        node=head
        while node and node.next:
            if node.val==node.next.val:
                new=node.next.next
                while new:
                    if not new:
                        break
                    if new.val==node.val:
                        new=new.next
                    else:
                        break
                node.next=new
            node=node.next
        return head
        
        

 

posted @ 2019-04-25 04:10  周洋  阅读(367)  评论(0编辑  收藏  举报