as a beginner this linked list problem cooked me
just started leetcode 5 days ago, upto array it was just bit uncomfortable, but I learnt linked List for the first time and oh my godd, that problem remove linked list elements just did me raw, on that specific case 7,7,7,7 it didn't pass cause I was stucking at doing 0 index logic correctly I even did that to but just this line took my whole 2 hoursss,
node = head
#full code
class Solution:
def removeElements(self, head: Optional[ListNode], val: int) -> Optional[ListNode]:
node = head
while head and head.val ==val:
head = head.next if head.next else None
node = head
while head and head.next:
if head.next.val == val:
head.next = head.next.next
else:
head = head.next
return nodeclass Solution:
def removeElements(self, head: Optional[ListNode], val: int) -> Optional[ListNode]:
node = head
while head and head.val ==val:
head = head.next if head.next else None
node = head
while head and head.next:
if head.next.val == val:
head.next = head.next.next
else:
head = head.next
return node
however Im not complaining and whining, just telling, I really got this spark or thing like this many days after, Ik 2 hours isnt valid on ts problem but it is what it is