【LintCode 简单】112. 删除排序链表中的重复元素
2018-01-20 15:11
513 查看
1.问题描述:
2.样例:
给出
给出
3.代码:"""
Definition of ListNode
class ListNode(object):
def __init__(self, val, next=None):
self.val = val
self.next = next
"""
class Solution:
"""
@param: head: head is the head of the linked list
@return: head of linked list
"""
def deleteDuplicates(self, head):
# write your code here
if head is None:
return head
pre=head
cur=head.next
while cur:
if pre.val<cur.val:
pre=cur
cur=cur.next
else:
pre.next=cur.next
cur=cur.next
return head
给定一个排序链表,删除所有重复的元素每个元素只留下一个。
2.样例:给出
1->1->2->null,返回
1->2->null
给出
1->1->2->3->3->null,返回
1->2->3->null
3.代码:"""
Definition of ListNode
class ListNode(object):
def __init__(self, val, next=None):
self.val = val
self.next = next
"""
class Solution:
"""
@param: head: head is the head of the linked list
@return: head of linked list
"""
def deleteDuplicates(self, head):
# write your code here
if head is None:
return head
pre=head
cur=head.next
while cur:
if pre.val<cur.val:
pre=cur
cur=cur.next
else:
pre.next=cur.next
cur=cur.next
return head
相关文章推荐
- 112. 删除排序链表中的重复元素(remove-duplicates-from-sorted-list)(c++)----lintcode面试题之链表
- [LintCode]112.删除排序链表中的重复元素
- LintCode-112.删除排序链表中的重复元素
- LintCode 删除排序链表中的重复元素
- LintCode 删除排序链表中的重复元素
- lintcode 容易题:Remove Duplicates from Sorted List 删除排序链表中的重复元素
- 112. 删除排序链表中的重复元素
- Lintcode112.删除排序链表中的重复元素
- LintCode刷题阶段性总结---链表容易篇(翻转链表,删除链表重复元素,合并两个排序链表等)
- LintCode 删除排序链表中的重复元素
- LintCode-删除排序链表中的重复元素
- lintcode ----删除排序链表中的重复元素
- 删除排序链表中的重复元素-LintCode
- 删除排序链表中的重复元素-LintCode
- 112. 删除排序链表中的重复元素
- LintCode-删除排序链表中的重复元素
- python_lintcode_115不同的路径 II_112删除排序链表中的重复元素
- lintcode-删除排序链表中的重复数字II-113
- lintcode 112 删除排序链表中的重复元素
- 删除排序链表中重复元素