您的位置:首页 > 编程语言 > Python开发

leetcode之Remove Duplicates from Sorted List

2015-11-30 19:31 369 查看
这题没啥好说的,依次比较即可。
# Definition for singly-linked list.
# class ListNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution(object):
def deleteDuplicates(self, head):
"""
:type head: ListNode
:rtype: ListNode
"""
if head == None:
return None
list1 = head
p = list1.val
while list1.next != None:
if list1.next.val == p:
list1.next = list1.next.next
continue
else:
p = list1.next.val
list1 = list1.next
return head
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息