LeetCode 083 Remove Duplicates from Sorted List

LeetCode 083 Remove Duplicates from Sorted List Problem

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

class Solution(object):
    # def deleteDuplicates(self, head):
    #     """
    #     :type head: ListNode
    #     :rtype: ListNode
    #     """
    #     if head is None:
    #         return None
    #     temp = ListNode(2147483647)
    #     temp.next = head
    #     pos = head
    #     head = temp
    #     last = head
    #     while pos is not None:
    #         if last.val == pos.val:
    #             last.next = pos.next
    #         else:
    #             last = pos
    #         pos = pos.next
    #     return head.next

    def deleteDuplicates(self, head):
        if head is None:
            return None
        pos = head
        while pos is not None and pos.next is not None:
            if pos.val == pos.next.val:
                pos.next = pos.next.next
            else:
                pos = pos.next
        return head
Download Remove Duplicates from Sorted List.py

List of all Remove Duplicates from Sorted List problems

Leetcode 083 Remove Duplicates from Sorted List problem solution in python3 with explanation. This is the best place to expand your knowledge and get prepared for your next interview.

Feedback is the most important part of any website.

If you have any query, suggestion or feedback, Please feel free to contact us.