# 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
"""
if head==None:return None
ans=head
while(head.next!=None):
if head.next.val==head.val:
head.next=head.next.next
else:
head=head.next
return ansLeetCode-83-Remove Duplicates from Sorted List 链表水题
最新推荐文章于 2023-12-10 17:16:02 发布
本文介绍了一种在单链表中删除所有重复节点的方法。通过一个简单的Python类定义了链表节点,并提供了一个名为deleteDuplicates的函数来实现该功能。该函数遍历链表并移除所有值相同的相邻节点。
296

被折叠的 条评论
为什么被折叠?



