题目描述
1 |
Given a linked list, remove the nth node from the end of list and return its head. |
解题思路
- 先获取List的长度,获取需要删除的第n个节点的前一个节点
- 如果当前节点是head,返回head.next
- 否则,将prev.next设置为current.next
Python实现1
1 |
class (object): |
Runtime: 59 ms
1 |
Given a linked list, remove the nth node from the end of list and return its head. |
1 |
class (object): |
Runtime: 59 ms
近期评论