用python语言解答LeetCode的82题
方法一
方法一的代码:
#coding:utf-8
class ListNode:
def init(self, x):
self.val = x
self.next = None
class Solution:
def deleteDuplicates(self, head):
“””
:param head: ListNode
:return: ListNode
"""
thead = ListNode(0)
thead.next = head
pre, cur = None, thead
while cur:
pre = cur
cur = cur.next
while cur and cur.next and cur.next.val == cur.val:
t = cur.val
while cur and cur.val == t:
cur = cur.next
pre.next = cur
return thead.next