deletDuplicateds

来源:互联网 发布:加内特生涯平均数据 编辑:程序博客网 时间:2024/04/29 07:21

问题描述:删除链表中值一样的节点

本题收获:

1,首先判断节点是否为空

2,在链表进行循环的过程中,应该以a.next作为判断条件

3,当赋值情况不同时,不能简写判断语句

class Solution(object):    def deleteDuplicates(self, head):        """        :type head: ListNode        :rtype: ListNode        """        a = head        if not a:            return a        while a.next:            if a.val == a.next.val:                a.next = a.next.next            else:                a = a.next        return head

原创粉丝点击