1. How I sloved
I had to make a linked list without duplicate values. So if the value of ‘cur’ was equal to the value of ‘cur.next’, ‘cur’ was connected to ‘cur.next.next’. Otherwise, ‘cur’ just moved to ‘next’. Then head was returned.
2. Code
class Solution:
def deleteDuplicates(self, head: ListNode) -> ListNode:
if head == None:
return
cur = head
while cur:
if cur.val == cur.next.val:
cur.next = cur.next.next
else:
cur = cur.next
return head
3. Result
Runtime : 36 ms(93.93%), Memory usage : 14 MB(100.00%)
(Runtime can be different by a system even if it is a same code.)