国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專(zhuān)欄INFORMATION COLUMN

[LintCode] Identical Binary Tree

zoomdong / 1706人閱讀

problem

Check if two binary trees are identical. Identical means the two binary trees have the same structure and every identical position has the same value.

Example
    1             1
   /            / 
  2   2   and   2   2
 /             /
4             4
are identical.

    1             1
   /            / 
  2   3   and   2   3
 /               
4                 4
are not identical.
Solution
public class solution {
    public boolean isIdentical(TreeNode a, TreeNode b) {
        if (a == null && b == null) return true;
        if (a == null || b == null) return false;
        return a.val == b.val && isIdentical(a.left, b.left) && isIdentical(a.right, b.right);
    }
}

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

轉(zhuǎn)載請(qǐng)注明本文地址:http://m.specialneedsforspecialkids.com/yun/65411.html

相關(guān)文章

  • tweaked identical binary tree

    摘要:原題檢查兩棵二叉樹(shù)是否在經(jīng)過(guò)若干次扭轉(zhuǎn)后可以等價(jià)。扭轉(zhuǎn)的定義是,交換任意節(jié)點(diǎn)的左右子樹(shù)。等價(jià)的定義是,兩棵二叉樹(shù)必須為相同的結(jié)構(gòu),并且對(duì)應(yīng)位置上的節(jié)點(diǎn)的值要相等。樣例是扭轉(zhuǎn)后可等價(jià)的二叉樹(shù)。 原題檢查兩棵二叉樹(shù)是否在經(jīng)過(guò)若干次扭轉(zhuǎn)后可以等價(jià)。扭轉(zhuǎn)的定義是,交換任意節(jié)點(diǎn)的左右子樹(shù)。等價(jià)的定義是,兩棵二叉樹(shù)必須為相同的結(jié)構(gòu),并且對(duì)應(yīng)位置上的節(jié)點(diǎn)的值要相等。注意:你可以假設(shè)二叉樹(shù)中不會(huì)有重復(fù)...

    frontoldman 評(píng)論0 收藏0
  • [LintCode] Check Full Binary Tree

    Description A full binary tree is defined as a binary tree in which all nodes have either zero or two child nodes. Conversely, there is no node in a full binary tree, which has one child node. More in...

    Keven 評(píng)論0 收藏0
  • [LintCode/LeetCode] Balanced Binary Tree

    摘要:根據(jù)二叉平衡樹(shù)的定義,我們先寫(xiě)一個(gè)求二叉樹(shù)最大深度的函數(shù)。在主函數(shù)中,利用比較左右子樹(shù)的差值來(lái)判斷當(dāng)前結(jié)點(diǎn)的平衡性,如果不滿(mǎn)足則返回。 Problem Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as...

    morgan 評(píng)論0 收藏0
  • [LintCode] Insert Node in a Binary Search Tree

    摘要:建立兩個(gè)樹(shù)結(jié)點(diǎn),先用找到在的位置,讓作為的根節(jié)點(diǎn)找到的位置后,指向。此時(shí),用代替與連接就可以了。 Problem Given a binary search tree and a new tree node, insert the node into the tree. You should keep the tree still be a valid binary search tr...

    Taste 評(píng)論0 收藏0
  • [LintCode] Remove Node in Binary Search Tree [理解BS

    Problem Given a root of Binary Search Tree with unique value for each node. Remove the node with given value. If there is no such a node with given value in the binary search tree, do nothing. You sho...

    陳江龍 評(píng)論0 收藏0

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

0條評(píng)論

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