zoukankan      html  css  js  c++  java
  • [LeetCode]题解(python):083-Remove Duplicates from Sorted List

    题目来源:

      https://leetcode.com/problems/remove-duplicates-from-sorted-list/


    题意分析:

      给定一个排好序的链表,返回一个链表使得这个链表每个元素只出现一次。


    题目思路:

      这题和上题思路类似也是考链表知识点,将重复的去掉。


    代码(Python):

      

     1 # Definition for singly-linked list.
     2 # class ListNode(object):
     3 #     def __init__(self, x):
     4 #         self.val = x
     5 #         self.next = None
     6 
     7 class Solution(object):
     8     def deleteDuplicates(self, head):
     9         """
    10         :type head: ListNode
    11         :rtype: ListNode
    12         """
    13         tmp = ListNode(-1)
    14         tmp.next = head
    15         while tmp.next != None:
    16             if tmp.val == tmp.next.val:
    17                 tmp.next = tmp.next.next
    18             else:
    19                 tmp = tmp.next
    20         return head
    View Code

    转载请注明出处:http://www.cnblogs.com/chruny/p/5088614.html 

  • 相关阅读:
    简易计算机
    作业-继承
    exception
    作业-窗口
    作业-数字
    作业8
    作业9-1
    作业9-2
    book
    成绩录入
  • 原文地址:https://www.cnblogs.com/chruny/p/5088614.html
Copyright © 2011-2022 走看看