package
0.0.0-20241220224003-b7cf03a90b2b
Repository: https://github.com/szhou12/leetcode-go.git
Documentation: pkg.go.dev
# README
19. Remove Nth Node From End of List
Solution idea
Two pointers: 同向而行
Key 1: 两个指针相隔k步时同时往前走,第一个指针走到底时,第二个指针指向的就是倒数第k个
Key 2: 加一个dummy head 防止因为删掉的是第一个指针而导致null pointer exception
Time complexity = $O(n)$