finish 83
This commit is contained in:
parent
89e23e7654
commit
e02270f6bd
23
leetcode/83.py
Normal file
23
leetcode/83.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# Given the head of a sorted linked list,
|
||||||
|
# delete all duplicates such that each element appears only once.
|
||||||
|
# Return the linked list sorted as well.
|
||||||
|
|
||||||
|
# Definition for singly-linked list.
|
||||||
|
class ListNode:
|
||||||
|
def __init__(self, val=0, next=None):
|
||||||
|
self.val = val
|
||||||
|
self.next = next
|
||||||
|
|
||||||
|
from typing import Optional
|
||||||
|
class Solution:
|
||||||
|
def deleteDuplicates(self, head: Optional[ListNode]) -> Optional[ListNode]:
|
||||||
|
if head is None:
|
||||||
|
return head
|
||||||
|
pointer = head
|
||||||
|
while pointer.next is not None:
|
||||||
|
if pointer.val == pointer.next.val:
|
||||||
|
pointer.next = pointer.next.next
|
||||||
|
else:
|
||||||
|
pointer = pointer.next
|
||||||
|
|
||||||
|
return head
|
Loading…
x
Reference in New Issue
Block a user