1

愿python的天堂里没有指针。

# -*- coding:utf-8 -*-
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution:
    def deleteDuplication(self, pHead):
        # 前驱结点指针
        pre_node = None
        # 当前节点指针
        p = pHead
        while p:
            # 下一个节点的指针
            next_node = p.next
            # 如果下一个节点存在,而且当前节点的值等于下一个节点的值,则需要进行删除操作
            if next_node and p.val == next_node.val:
                # 需要删除的值,用于删除连续的重复值
                dup_value = p.val
                # 连续删除,把next_node指针后移
                while next_node and next_node.val == dup_value:
                    next_node = next_node.next
                # 删除的点为头节点
                if not pre_node:
                    pHead = next_node
                # 将前驱节点连接到下一个不重复的值上
                else:
                    pre_node.next = next_node
                # 运算后移
                p = next_node
            else:
                pre_node = p
                p = p.next
        return pHead

PETCoder亚洲善待程序猿组织
225 声望33 粉丝

Sorry, but I have to leave.-Weibo