[leetcode]237. Delete Node in a Linked List

[leetcode]237. Delete Node in a Linked List


Analysis

厉害的人总是那么的厉害呀~—— [菜鸡反省中~]

Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.
删除链表中的给定节点。

Implement

/**
 * 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;
    }
};

猜你喜欢

转载自blog.csdn.net/weixin_32135877/article/details/80680435