Skip to main content

Remove Duplicates from Sorted List


Given a sorted linked list, delete all duplicates such that each element appears only once and return the new head of the list.

Example 1
Input: 1 -> 1 -> 2
Output: 1 -> 2


all//Remove Duplicates from Sorted

# Definition for singly-linked list.
class ListNode:
def __init__(self, x):
self.val = x = None

class Solution:
def deleteDuplicates(self, head):
node = head
while node and
if node.val == =
node =
return head