zoukankan      html  css  js  c++  java
  • 链表_leetcode82

    # 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 or not head.next:
    return head

    dummyHead = ListNode(0)
    dummyHead.next = head
    pre = dummyHead

    curNode = head
    nextNode = curNode.next
    curVal = curNode.val
    unique = True

    while curNode and nextNode:

    if curNode.val == curVal and nextNode.val == curVal:
    unique = False
    curNode = nextNode
    nextNode = nextNode.next
    continue

    if curNode.val == curVal and nextNode.val != curVal and not unique:
    curNode = nextNode
    nextNode = nextNode.next
    curVal = curNode.val
    unique = True
    continue

    else:
    pre.next = curNode
    pre = pre.next

    curNode = nextNode
    nextNode=nextNode.next
    curVal = curNode.val
    unique = True

    if curNode.val == curVal and not unique:
    pre.next = None

    if curNode.val == curVal and unique:
    pre.next = curNode


    return dummyHead.next
  • 相关阅读:
    Win10系统下安装Tensorflow
    基于theano的深度卷积神经网络
    卷积层和池化层
    ReLu(Rectified Linear Units)激活函数
    向上取整&向下取整
    物品选取
    猫狗大战
    田忌赛马
    魔术棋子
    回文字串
  • 原文地址:https://www.cnblogs.com/lux-ace/p/10557155.html
Copyright © 2011-2022 走看看