删除链表中重复的结点
来源:互联网 发布:sql distinct 数量 编辑:程序博客网 时间:2024/06/10 16:29
删除链表中重复的结点
在一个排序的链表中,存在重复的结点,请删除该链表中重复的结点,重复的结点不保留,返回链表头指针。 例如,链表1->2->3->3->4->4->5 处理后为 1->2->5
参考代码:
# -*- coding:utf-8 -*-# class ListNode:# def __init__(self, x):# self.val = x# self.next = Noneclass Solution: def deleteDuplication(self, pHead): # write code here if not pHead : #or not pHead.next return pHead lst = [] node = pHead tmp = None while node: if node.val == tmp: node = node.next elif node.next and node.val == node.next.val: tmp = node.val node = node.next.next else: lst+=[node] node = node.next for x in range(len(lst)-1): lst[x].next = lst[x+1] if not lst : return lst[-1].next = None return lst[0]
0 0
- 删除链表中重复的结点
- 删除链表中重复的结点
- 删除链表中重复的结点
- 删除链表中重复的结点
- 删除链表中重复的结点
- 删除链表中重复的结点
- 删除链表中重复的结点
- 删除链表中重复的结点
- 删除链表中重复的结点
- 删除链表中重复的结点
- 删除链表中重复的结点
- 删除链表中重复的结点
- 删除链表中重复的结点
- 删除链表中重复的结点
- 删除链表中重复的结点
- 删除链表中重复的结点
- 删除链表中重复的结点
- 删除链表中重复的结点
- 网易运维开发岗笔试题目
- 自动化测试框架设计
- poj1195——Mobile phones(二维树状数组)
- sql语句 (上 基础)
- SpringMVC的相关的信息
- 删除链表中重复的结点
- sql语句 (中 基础)
- Object 对象方法 hasOwnProperty()
- Redis数据结构之字典
- linux下如何安装redis
- android通知对话框、多选对话框、单选对话框
- Plupload
- window<->linux移植
- 雪花飘落插件