Leetcode237. Delete Node in a Linked List

Posted 业精于勤荒于嬉,行成于思毁于随

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Leetcode237. Delete Node in a Linked List相关的知识,希望对你有一定的参考价值。

/**
 * 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) {
        ListNode * lastNode = node;
        while (node->next != NULL) {
            node->val = node->next->val;
            lastNode = node;
            node = node->next;
        }
        lastNode->next = NULL;
        delete node;      
    }
};

 

Your runtime beats 100.00 % of cpp submissions.

以上是关于Leetcode237. Delete Node in a Linked List的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode笔记:237. Delete Node in a Linked List

LeetCode237-delete-node-in-a-linked-list

[LeetCode]237. Delete Node in a Linked List

Leetcode237. Delete Node in a Linked List

[LeetCode] 237. Delete Node in a Linked List

LeetCode OJ 237Delete Node in a Linked List