Lintcode 372. O(1)时间复杂度删除链表节点

-----------------------------------

AC代码:

/**
 * Definition for ListNode.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int val) {
 *         this.val = val;
 *         this.next = null;
 *     }
 * }
 */ 
public class Solution {
    /**
     * @param node: the node in the list should be deleted
     * @return: nothing
     */
    public void deleteNode(ListNode node) {
        if(node==null){
            return ;
        }else if(node.next==null){
            node=null;
            return;
        }
        while(node.next.next!=null){
            node.val=node.next.val;
            node=node.next;
        }
        node.val=node.next.val;
        node.next=null;
    }
}

题目来源: http://www.lintcode.com/zh-cn/problem/delete-node-in-the-middle-of-singly-linked-list/

原文地址:https://www.cnblogs.com/cc11001100/p/6241845.html