https://leetcode.com/problems/remove-duplicates-from-sorted-list/
Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such this each element appear only once.
For example,
Given 1->1->2
, return 1->2
.
Given 1->1->2->3->3
, return 1->2->3
.
Title: Removing duplicates of an ordered list
1 #Definition for singly-linked list.2 #class ListNode:3 #def __init__ (self, x):4 #self.val = x5 #Self.next = None6 7 classSolution:8 #@param {ListNode} head9 #@return {ListNode}Ten defdeleteduplicates (Self, head): One ifHead==noneorhead.next==None: A returnHead -p=Head - whileP.next:#the previous if judgment is guaranteed to p!=none at this time, only to judge P.next the ifP.val==p.next.val:#if the P-value is equal to the P.next value at this time -P.next=p.next.next#Remove the P.next and connect directly to the p.next.next without changing p, while still comparing p and p.next at this time - Else: -P=p.next#if the p and P.next values are not equal, move the position of P and start judging the next node and the values followed. + returnHead
Remove Duplicates from Sorted List