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/

相关文章:

  • 2021-10-31
  • 2021-08-30
  • 2021-09-15
  • 2022-12-23
  • 2022-01-05
  • 2021-07-18
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-03
  • 2021-06-05
  • 2022-12-23
  • 2022-12-23
  • 2021-04-16
  • 2021-10-11
  • 2022-12-23
相关资源
相似解决方案