[LeetCode] 83. Remove Duplicates from Sorted List
Python
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def deleteDuplicates(self, head: Optional[ListNode]) -> Optional[ListNode]:
cur = head
while cur :
if cur.next and cur.val == cur.next.val :
cur.next = cur.next.next
else :
cur = cur.next
return head
댓글남기기