237. 删除链表中的节点

    xiaoxiao2025-06-09  25

    思路:将该节点后一个节点的值赋过来,然后删除后一个节点。

    /** * 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->val=node->next->val; node->next=node->next->next; } };

    执行用时 : 16 ms, 在Delete Node in a Linked List的C++提交中击败了98.78% 的用户 内存消耗 : 9.3 MB, 在Delete Node in a Linked List的C++提交中击败了5.55% 的用户

    最新回复(0)