题目来源:
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