# Definition for singly-linked list.# class ListNode(object):# def __init__(self, x):# self.val = x# self.next = NoneclassSolution(object):defdeleteDuplicates(self,head):""" :type head: ListNode :rtype: ListNode """node=ListNode(-1)ret=nodewhilehead!=None:nextNode=head.next# find next nodeifnextNode!=NoneandnextNode.val==head.val:whilenextNode!=NoneandnextNode.val==head.val:nextNode=nextNode.nextelse:# found non-duplicated nodesnode.next=headnode=head# in case there is no other nodenode.next=Nonehead=nextNodereturnret.next