Skip to content

Commit

Permalink
feat: solve problem 19
Browse files Browse the repository at this point in the history
  • Loading branch information
orgball2608 committed Jul 27, 2024
1 parent be14e73 commit dff82a8
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions medium/19. Remove Nth Node From End of List.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package medium

func removeNthFromEnd(head *ListNode, n int) *ListNode {
//dummy node
dummyNode := &ListNode{0, head}
fast, slow := dummyNode, dummyNode
for i := 0; i <= n; i++ {
fast = fast.Next
}

for fast != nil {
fast = fast.Next
slow = slow.Next
}

slow.Next = slow.Next.Next

return dummyNode.Next
}

//Time: O(N)
//Space: O(1)

0 comments on commit dff82a8

Please sign in to comment.