视频讲解
代码
class Solution:
def removeNthFromEnd(self, head: ListNode, n: int) -> ListNode:
# create dummy head
dummy_head = ListNode(0)
dummy_head.next = head
# create two pointers left and right
left = dummy_head
right = dummy_head
for _ in range(n):
right = right.next
# shift left and right
while right.next:
left = left.next
right = right.next
# delete prev.next
prev = left
succ = left.next.next
prev.next = succ
# return
return dummy_head.next
PPT讲解
本题涉及的知识点:
我的 Leetcode 讲解频道
代码链接
面试高频考点Youtube链接
- 数组(Array)
- 哈希表(Hash Table)
- 链表(Linked List)
- 数学(Math)
- 链表(Linked List)
- 双指针(Two Pointers)
- 字符串(String)
- 二分查找(Binary Search)
- 分治(Divide and Conquer)
- 动态规划(Dynamic Programming)
- 回溯(Backtracking)
- 栈(Stack)
- 堆(Heap)
- 贪心算法(Greedy)
- 排序(Sort)
- 树(Tree)
- 深度优先搜索(Depth-First Search)
- 广度优先搜索(Breadth-First Search)
- 二叉查找树(Binary Search Tree)
- 递归(Recursion)
- 队列(Queue)
- 移动窗口(Sliding Window)