83. Remove Duplicates from Sorted List Leetcode Python
来源:互联网 发布:传奇单机版物品数据库 编辑:程序博客网 时间:2024/05/22 05:11
Given a sorted linked list, delete all duplicates such that each element appear only once.
For example,
Given 1->1->2, return 1->2.
For example,
Given 1->1->2, return 1->2.
Given 1->1->2->3->3, return 1->2->3.
定义一个pre 和cur
1.当二者不等的时候pre.next=cur pre=pre.next
2.当相等的时候pre.next=cur.next
3.每步都是cur=cur.next
代码如下:
# Definition for singly-linked list.# class ListNode:# def __init__(self, x):# self.val = x# self.next = Noneclass Solution: # @param head, a ListNode # @return a ListNode def deleteDuplicates(self, head): if head==None or head.next==None: return head dummy=ListNode(0) dummy.next=head pre=dummy.next cur=dummy.next while cur: if pre.val!=cur.val: pre.next=cur pre=pre.next else: pre.next=cur.next cur=cur.next return dummy.next
0 0
- Leetcode-Remove Duplicates from Sorted List-Python
- 83. Remove Duplicates from Sorted List Leetcode Python
- [leetcode:python]83.Remove Duplicates from Sorted List
- [LeetCode]83.Remove Duplicates from Sorted List
- [Leetcode] 83. Remove Duplicates from Sorted List
- LeetCode --- 83. Remove Duplicates from Sorted List
- [leetcode] 83.Remove Duplicates from Sorted List
- LeetCode 83. Remove Duplicates from Sorted List
- 【leetcode】83. Remove Duplicates from Sorted List
- 83. Remove Duplicates from Sorted List LeetCode
- leetcode 83. Remove Duplicates from Sorted List
- [LeetCode]83. Remove Duplicates from Sorted List
- 【LeetCode】83. Remove Duplicates from Sorted List
- LeetCode 83. Remove Duplicates from Sorted List
- [leetcode] 83. Remove Duplicates from Sorted List
- leetcode 83. Remove Duplicates from Sorted List
- LeetCode *** 83. Remove Duplicates from Sorted List
- LeetCode - 83. Remove Duplicates from Sorted List
- js中的hashmap实现
- python输入和输出
- Ubuntu14.04上安装Ruby/tk
- 二分搜索的区间问题
- hibernate 连接Mysql数据库插入中文数据变问号 解决方法
- 83. Remove Duplicates from Sorted List Leetcode Python
- 2015年2月4日工作日志
- Unity3D_IOS 研究院之IOS高级界面发送消息与Unity3D消息的接收(九)
- 图论相关的算法
- Uva-1590 - IP Networks-AC
- EasyPR--开发详解(6)SVM开发详解
- MyBatis之传入参数
- 发布mvc报错:403.14-Forbidden Web 服务器被配置为不列出此目录的内容
- 排序算法二:选择排序