IT常识
技术 Python PHP JavaScript IOS Android Java 数据库 资源 公众号 代码片段 github
  • IT常识
  • 技术

Lintcode 469. 等价二叉树

Posted 2020-08-26

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Lintcode 469. 等价二叉树相关的知识,希望对你有一定的参考价值。

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

 

AC代码:

/**
 * Definition of TreeNode:
 * public class TreeNode {
 *     public int val;
 *     public TreeNode left, right;
 *     public TreeNode(int val) {
 *         this.val = val;
 *         this.left = this.right = null;
 *     }
 * }
 */
public class Solution {
    /**
     * @param a, b, the root of binary trees.
     * @return true if they are identical, or false.
     */
    public boolean isIdentical(TreeNode a, TreeNode b) {
        if(a==null && b==null) return true;
        else if(a==null || b==null) return false;
        else if(a.val!=b.val) return false;
        return isIdentical(a.left,b.left) && isIdentical(a.right,b.right);
    }
}

 

 

题目来源: http://www.lintcode.com/zh-cn/problem/identical-binary-tree/

以上是关于Lintcode 469. 等价二叉树的主要内容,如果未能解决你的问题,请参考以下文章

lintcode:等价二叉树

Lintcode 97.二叉树的最大深度

Lintcode---二叉树的序列化和反序列化

lintcode:二叉树的所有路径

lintcode 66.67.68 二叉树遍历(前序中序后序)

LintCode 93. 平衡二叉树

(c)2006-2024 SYSTEM All Rights Reserved IT常识