自己1:想使用暴力破解法,采用遍历链表将不重复的数据单独拉一个list出来再重新建立一个新的链表进行返回,但是结果超出了时间限制: # Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = x # self.next = None class Solution(object): def deleteDuplicates(self, head): """ :type head: ListNode :rtype: ListNode """ res_list = list() res = ListNode(-1) p = head while p: if p.val in res_list: res_list.remove(int(p.val)) else: res_list.append(int(p.val)) res_list = res_list[::-1] for i in res_list: tmp = ListNode(i) tmp.next = res.next res.next = tmp return res 大佬1:大佬通过设立两个前后节点,如果发现有相同的数据就不断的将后节点后移,直至与数据不同在重新重置前后节点,并将列表中前节点的数据抛弃。 thead = ListNode(-1) 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