
自己1:行吧,时间已经击败99%的人了,不想优化了,bingo
# 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 not head:
return None
res = ListNode(-1)
res.next = head
pre = head
tail = head.next
while tail:
if pre.val != tail.val:
pre.next = tail
pre = tail
tail = tail.next
else:
tail = tail.next
pre.next = tail
return res.next
本文介绍了一种高效的单链表节点去重算法,通过一次遍历实现相邻重复节点的删除,提高了链表数据结构的操作效率。
468

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



