成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

[LintCode] Delete Node in the Middle of Singly Li

lowett / 693人閱讀

Problem

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

Note

就是把node.next.val賦給node,然后刪掉node.next,用node直接連接node.next.next。

Solution
public class Solution {
    public void deleteNode(ListNode node) {
        if (node == null) return;
        if (node.next != null) {
            node.val = node.next.val;
            node.next = node.next.next;
        }
        return;
    }
}

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/65536.html

相關(guān)文章

  • [Lintcode] Nth to Last Node in List 鏈表倒數(shù)第N個(gè)節(jié)點(diǎn)

    摘要:遞歸法復(fù)雜度時(shí)間空間思路當(dāng)遞歸到鏈表尾部時(shí)返回,每次返回時(shí)長(zhǎng)度加,一旦長(zhǎng)度為時(shí)記錄下該節(jié)點(diǎn)。雙指針法復(fù)雜度時(shí)間空間思路用兩個(gè)指針,快指針先走步,然后快慢指針同時(shí)開始走,保持的距離,這樣當(dāng)快指針到達(dá)末尾時(shí),慢指針就是倒數(shù)第個(gè)。 Nth to Last Node in List Find the nth to last element of a singly linked list. ...

    CoXie 評(píng)論0 收藏0
  • [LintCode/LeetCode] Nth to Last Node in List

    摘要:依然是一道找倒數(shù)第個(gè)結(jié)點(diǎn)的鏈表題,用雙指針做。先走,然后和一起走,直到為,的位置就是倒數(shù)第個(gè)位置。 Problem Find the nth to last element of a singly linked list. The minimum number of nodes in list is n. Example Given a List 3->2->1->5->null ...

    Salamander 評(píng)論0 收藏0
  • [LintCode/LeetCode] Add Two Numbers

    Problem You have two numbers represented by a linked list, where each node contains a single digit. The digits are stored in reverse order, such that the 1s digit is at the head of the list. Write a f...

    hedzr 評(píng)論0 收藏0
  • [LintCode/LeetCode] Intersection of Two Linked Lis

    Problem Write a program to find the node at which the intersection of two singly linked lists begins. Example The following two linked lists: A: a1 → a2 ↘ ...

    OldPanda 評(píng)論0 收藏0
  • [LeetCode/LintCode] Odd Even Linked List

    Problem Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes. Example Example:Given...

    awokezhou 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<