# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def deleteDuplicates(self, head: ListNode) -> ListNode:
if not head: return None
slow = head
fast = head.next
while fast:
if fast.val != slow.val:
slow.next = fast
slow = slow.next
fast = fast.next
slow.next = None
return head
每日一道Leetcode - 83. 删除排序链表中的重复元素【双指针|快慢指针】
最新推荐文章于 2021-07-30 12:21:51 发布