kucheasysa

Algoverse_adesh_40

Jul 9th, 2024
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. # Definition for singly-linked list.
  2. # class ListNode:
  3. #     def __init__(self, val=0, next=None):
  4. #         self.val = val
  5. #         self.next = next
  6. class Solution:
  7.     def removeElements(self, head: Optional[ListNode], val: int) -> Optional[ListNode]:
  8.         if head==None:
  9.             return head
  10.         while head and head.val==val:
  11.             head=head.next
  12.         res=head
  13.         while res:
  14.             while res.next and res.next.val==val:
  15.                 res.next=res.next.next
  16.             res=res.next
  17.         return head
Advertisement
Add Comment
Please, Sign In to add comment