呓语Beta 2.0 首页 镜头后 灶台前 捐赠者名单 有趣的小站

leetcode 83 Remove Duplicates From Sorted List

文档信息

leetcode 83 Remove Duplicates From Sorted List

解法一

# 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
        """
        curr = head
        while curr != None and curr.next != None:
            if curr.val == curr.next.val: # 发现重复值,跳过,但curr不移动,继续检测后面的值还有没有重复的
                curr.next = curr.next.next
            else:
                curr = curr.next # 值不同,curr后移
        return head

note

捐赠支持

可以使用支付宝转帐给richard.ma.19850509#gmail.com(请将#替换为@),谢谢!

Fork me on GitHub