mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-08-06 18:24:23 +08:00
879 B
879 B
题目地址
https://leetcode-cn.com/problems/delete-node-in-a-linked-list/
思路
题目中已经说了是非末尾节点,所以不用对末尾节点的情况经行判断
链表中所有节点的值都是唯一的。 题目题意强调这一点,是为什么,因为 我们删除的node在内存地址 删除的并不是这个。
代码
class Solution {
public:
void deleteNode(ListNode* node) {
node->val = node->next->val;// 将前一个值赋给当前node
node->next = node->next->next; // 将当前node的next 指向下下node
}
};
笔者在先后在腾讯和百度从事技术研发多年,利用工作之余重刷leetcode,本文 GitHub:https://github.com/youngyangyang04/leetcode-master 已经收录,欢迎star,fork,共同学习,一起进步。