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;
    }

}

};

posted @ 2015-11-22 10:31  CathyXiaohe  阅读(117)  评论(0编辑  收藏  举报