Leetcode83 删除排序链表中的重复元素

2019年12月3日 0 作者 折纸

题目描述

file

解法

# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None
from collections import defaultdict
class Solution:
    def deleteDuplicates(self, head: ListNode) -> ListNode:
        cur = head
        if not head:
            return None
        while(cur and cur.next):
            if(cur.val == cur.next.val):
                tmp = cur.next
                cur.next = tmp.next
                del tmp
            else:
                cur = cur.next
        return head

 

Note

  • 我太菜了