Remove Duplicates from Sorted List
来源:互联网 发布:淘宝床单四件套梦洁 编辑:程序博客网 时间:2024/06/03 21:55
题目:
Given a sorted linked list, delete all duplicates such that each element appear only once.
For example,
Given 1->1->2
, return 1->2
.
Given 1->1->2->3->3
, return 1->2->3
.
此题简单,但未一次通过。
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
# @param {ListNode} head
# @return {ListNode}
def deleteDuplicates(self, head):
p = head
if head==None:return head
while p.next:
if p.val==p.next.val:
p.next=p.next.next
else:
p = p.next
return head
0 0
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove duplicates from sorted list
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- android实习期日常笔记(三)
- extjs-->grid
- java对redis的一些基本操作
- css基础
- Ubutu Kylin 14.10 远程桌面的使用
- Remove Duplicates from Sorted List
- C1020: 意外的 #endif
- Android 开发过程中物理返回键的运用(仿qq退出应用,仍在后台执行,但不销毁)
- 收藏关于sql server的一些学习资料
- R12 Customer新建或更新时的工作过程 - DQM Serial Sync Index Program
- 浮动布局
- 在移动网络上创建更稳定的连接
- 插入排序(INSERTION_SORT)
- 简单的DOS批处理BATACH内部命令