78 leetcode - Remove Duplicates from Sorted List
来源:互联网 发布:西北师范大学知行 编辑:程序博客网 时间:2024/06/07 10:46
#!/usr/bin/python# -*- coding: utf-8 -*-'''Remove Duplicates from Sorted ListGiven 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(object): def __init__(self, x): self.val = x self.next = Noneclass Solution(object): def deleteDuplicates(self, head): """ :type head: ListNode :rtype: ListNode """ if head == None or head.next == None: return head ret = head cur = head head = head.next while head != None: if head.val != cur.val: cur.next = head cur = cur.next head = head.next cur.next = None return retif __name__ == "__main__": s = Solution() head = ListNode(1) t = head for i in [1,2,2,3,3,5,6]: t.next = ListNode(i) t = t.next t.next = None t = head while t != None: print t.val t = t.next t = s.deleteDuplicates(head) while t != None: print t.val t = t.next
0 0
- 78 leetcode - Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List :from LeetCode
- Leetcode - List - Remove Duplicates from Sorted List
- [leetcode][list] Remove Duplicates from Sorted List
- [leetcode][list] Remove Duplicates from Sorted List
- LeetCode: Remove Duplicates from Sorted List
- LeetCode: Remove Duplicates from Sorted List II
- [Leetcode] Remove Duplicates from Sorted List
- [Leetcode] Remove Duplicates from Sorted List II
- LeetCode: Remove Duplicates from Sorted List
- LeetCode: Remove Duplicates from Sorted List II
- [Leetcode] Remove Duplicates from Sorted List II
- leetcode 37: Remove Duplicates from Sorted List
- [leetcode] Remove Duplicates from Sorted List II
- [LeetCode] Remove Duplicates from Sorted List II
- [LeetCode] Remove Duplicates from Sorted List
- [leetcode] Remove Duplicates from Sorted List
- [leetcode] Remove Duplicates from Sorted List II
- Matlab使用过程中内存不足问题的总结
- FG-Index: Towards Verification-Free Query Processing on Graph Databases
- 【九度】题目1023:EXCEL排序
- caffe学习系列:训练自己的图片集(超详细教程)
- Android 通过WiFi进行ADB调试
- 78 leetcode - Remove Duplicates from Sorted List
- Tree树(设置单击选中与取消多选框)(设置树节点隐藏)
- input子系统三 核心层和处理器注册
- 几个有用的blog链接
- 移动客户端中高效使用SQLite
- [leetcode] 448. Find All Numbers Disappeared in an Array
- 漫步数学分析八——集合边界
- input子系统四 input事件处理
- new JSONArray(List<Map>).tostring()问题