최대 1 분 소요

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

댓글남기기