Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Definition for singly-linked list.
- # class ListNode:
- # def __init__(self, val=0, next=None):
- # self.val = val
- # self.next = next
- class Solution:
- def removeElements(self, head: Optional[ListNode], val: int) -> Optional[ListNode]:
- if head==None:
- return head
- while head and head.val==val:
- head=head.next
- res=head
- while res:
- while res.next and res.next.val==val:
- res.next=res.next.next
- res=res.next
- return head
Advertisement
Add Comment
Please, Sign In to add comment