zoukankan      html  css  js  c++  java
  • 36: Same Tree

    /************************************************************************/
            /*       36:      Same Tree                                          */
            /************************************************************************/
            /*
             *  Given two binary trees, write a function to check if they are equal or not.

    Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
             * */
            
            //判断两个二叉树是否完全一致 (递归解法)

     private Boolean IsSame(TreeNode nodeleft,TreeNode noderight) 
            {
                if(nodeleft==null&&noderight==null)
                {
                    return true;
                }
                if(nodeleft==null||noderight==null)
                {
                    return false;
                }
                return nodeleft.val==noderight.val&&IsSame(nodeleft.left, noderight.left)&&IsSame(nodeleft.right, noderight.right);
            }
            
            public boolean isSameTree(TreeNode p, TreeNode q) 
            {
                return IsSame(p,q);
            }
  • 相关阅读:
    2019年面试题1
    面试题
    vsftp多个用户公享同一个文件,但是权限不同
    centos7搭建ftp
    安装v2ra y
    centos7安装lamp
    日升昌面试题
    一些插件
    面试被怼集(字节跳动篇)
    TOMCAT原理详解及请求过程(转载)
  • 原文地址:https://www.cnblogs.com/theonemars/p/4254111.html
Copyright © 2011-2022 走看看