Question Name: Remove Duplicates from Sorted List
Solution to Remove Duplicates from Sorted List by LeetCode
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
# @param head, a ListNode
# @return a ListNode
def deleteDuplicates(self, head):
# Handle special case that the list is empty
if head == None: return head
current = head
# Travel the list until the second last node
while current.next != None:
if current.val == current.next.val:
# This element and the next one are the same.
# They are duplicate. We are going to remove
# the next node.
temp = current.next
current.next = current.next.next
current = current.next