这道题比较简单,不做过多的描述
给定一个排序链表,删除所有重复的元素每个元素只留下一个。
样例
给出 1->1->2->null
,返回 1->2->null
给出 1->1->2->3->3->null
,返回 1->2->3->null
""" Definition of ListNode class ListNode(object): def __init__(self, val, next=None): self.val = val self.next = next """ class Solution: """ @param: head: head is the head of the linked list @return: head of linked list """ def deleteDuplicates(self, head): if head is None: return head temp = head while temp.next is not None: if temp.next.val == temp.val: temp.next = temp.next.next else: temp = temp.next return head
原文地址:https://www.cnblogs.com/KanHin/p/8120260.html
时间: 2024-10-16 09:59:55