https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list/
一样,与之前作业一样的思路
class Solution:
def deleteDuplicates(self, head: ListNode) -> ListNode:
if head==None:return head
rst=head#慢指针
cur=head.next#快指针
while cur:#当快指针不为None时
if cur and head.val==cur.val:
head.next=cur.next#head.next本来是指向cur的,为了实现删除,改为指向cur.next
cur=cur.next#cur指针向后移
else:
head=cur#当不满足删除条件时,一起向后移
cur=cur.next
return rst
删除元素链接:https://blog.youkuaiyun.com/AliceRainly/article/details/104399090