237. 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) {
        if(node==NULL) return;
        node->val=node->next->val;
        node->next=node->next->next;
    }
};
posted @ 2016-08-08 10:45  弦断  阅读(94)  评论(0编辑  收藏  举报