372.Definition of ListNode

单项列表只能把后一个node中的所有数据copy到当前node再delete后一node。

/**
 * Definition of ListNode
 * class ListNode {
 * public:
 *     int val;
 *     ListNode *next;
 *     ListNode(int val) {
 *         this->val = val;
 *         this->next = NULL;
 *     }
 * }
 */


class Solution {
public:
    /*
     * @param node: the node in the list should be deletedt
     * @return: nothing
     */
    void deleteNode(ListNode * node) {
        // write your code here
        node->val = node->next->val;
        ListNode *tmp = node->next;
        node ->next = node->next->next;
        delete tmp;
    }
};
posted @ 2018-09-13 21:10  narjaja  阅读(112)  评论(0编辑  收藏  举报