题解 | #删除链表中重复的结点#

删除链表中重复的结点

http://www.nowcoder.com/practice/fc533c45b73a41b0b44ccba763f866ef

# -*- coding:utf-8 -*-时间复杂度为O(n)的解法,只需一次遍历
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None
class Solution:
    def deleteDuplication(self, pHead):
        # write code here
        a=ListNode(None)
        a.next=pHead
        r=a
        while(r.next and r.next.next):
            if r.next.val==r.next.next.val:
                d=r.next.val
                s=r.next.next
                while(s and s.val==d):
                    s=s.next
                r.next=s
            else:
                r=r.next
        return(a.next)

全部评论

相关推荐

程序员牛肉:这一眼假啊,基本上都是骗人的,不然就涉及到职位贪腐了,就像之前华为的OD事件,看你运气好不好了
点赞 评论 收藏
分享
我:“加班需要有加班工资。” hr:“为什么?” 哈哈哈哈哈哈哈离大谱
juntenor:你确实太理想化了,对社会不了解呀。这个和HR没有关系,这是国内特色,不然怎么还会有外包就这种逆天的存在呢。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务