Xiaohe-LeetCode 237 Delete Node in a Linked List
This is almost the best solution.16ms.
/**
* 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) {
if(node && node->next){
node->val = node->next->val;
node->next = node->next->next;
}
}
};