leecode 地址:https://leetcode.com/problems/remove-duplicates-from-sorted-list/description/
Given a sorted linked list, delete all duplicates such that each element appear only once.
For example,
Given 1->1->2, return 1->2.
Given 1->1->2->3->3, return 1->2->3.
class Solution:
def deleteDuplicates(self, head):
h = head
while h!=None:
while h.next != None and h.val == h.next.val:
h.next = h.next.next
h = h.next
return head
本文介绍了一种从已排序链表中移除所有重复元素的方法,使得每个元素只出现一次。通过迭代检查相邻节点并调整链接的方式实现,最终返回处理后的链表。
709

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



