欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

237. Delete Node in a Linked List

程序员文章站 2024-02-17 10:23:28
...

237. Delete Node in a Linked List

易错点:

顺序

class Solution {
public:
    void deleteNode(ListNode* node) {
        if (!node) return;
        ListNode* prev = nullptr;
        while (node -> next){
            node -> val = node->next ->val;
            prev = node;
            node = node -> next;
        }
        prev->next = nullptr;        
        return;
    }
};