关闭

237. Delete Node in a Linked List

90人阅读 评论(0) 收藏 举报
分类:

二十七号的。。。


Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.

Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value 3, the linked list should become 1 -> 2 -> 4 after calling your function.


/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    void deleteNode(ListNode* node) {
        *node=*node->next;
    }
};


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:56604次
    • 积分:2017
    • 等级:
    • 排名:千里之外
    • 原创:149篇
    • 转载:3篇
    • 译文:0篇
    • 评论:3条
    最新评论