码迷,mamicode.com
首页 > 其他好文 > 详细

Cracking the Coding Interview Q2.3

时间:2014-07-08 22:03:31      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   div   re   algorithm   

Implement an algorithm to delete a node in the middle of a single linked list, given only access to that node.

 

思路:复制后面节点的值,然后删除后面的节点。

注意:如果给定的节点是最后一个,则无解。。

 

    public static boolean deleteNode(LinkedListNode n) {
        if (n == null || n.next == null) {
            return false; // Failure
        } 
        LinkedListNode next = n.next; 
        n.data = next.data; 
        n.next = next.next; 
        return true;
    }

 

Cracking the Coding Interview Q2.3,布布扣,bubuko.com

Cracking the Coding Interview Q2.3

标签:style   blog   color   div   re   algorithm   

原文地址:http://www.cnblogs.com/jdflyfly/p/3830656.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!