237. 删除链表中的节点

考点

  • 智力题

题解

1
2
3
4
5
6
7
class Solution {
public:
void deleteNode(ListNode* node) {
node->val = node->next->val;
node->next = node->next->next;
}
};

思路

一道脑筋急转弯的题目

要求中提到并且保证给定的节点node不是链表中的最后一个节点,那么直接用下一个节点覆盖自己就行