Skip to content

Commit

Permalink
Merge pull request neetcode-gh#1533 from razer96/203-Remove-Linked-Li…
Browse files Browse the repository at this point in the history
…st-Element.go

203-Remove-Linked-List-Element.go
  • Loading branch information
dissesmac authored Dec 15, 2022
2 parents f54888f + 0719ab7 commit b9328e0
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions go/203-Remove-Linked-List-Element.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
func removeElements(head *ListNode, val int) *ListNode {
if head == nil {
return nil
}

curr := head

for curr.Next != nil {
if curr.Next.Val == val {
curr.Next = curr.Next.Next
} else {
curr = curr.Next
}
}

if head.Val == val {
return head.Next
}

return head
}

0 comments on commit b9328e0

Please sign in to comment.