解题思路
看到重复的跳一步
仅此而已
83. 删除排序链表中的重复元素
代码
# 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
"""
node = head
while node and node.next:
if node.val == node.next.val:
node.next = node.next.next # 删掉重复的
else:
node = node.next
return head

网友评论