博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
36: Same Tree
阅读量:4556 次
发布时间:2019-06-08

本文共 965 字,大约阅读时间需要 3 分钟。

/************************************************************************/

        /*       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);        }

 

转载于:https://www.cnblogs.com/theonemars/p/4254111.html

你可能感兴趣的文章
大道至简读后感
查看>>
hdu 1404
查看>>
ACM/ICPC 之 欧拉回路两道(POJ1300-POJ1386)
查看>>
避免死锁的银行家算法
查看>>
resultMap自定义某个javaBean的封装规则代码
查看>>
oracle tkprof 工具详解
查看>>
[Django实战] 第3篇 - 用户认证(初始配置)
查看>>
简单逆向分析修改软件标题
查看>>
20180607jquery实现切换变色
查看>>
框架大集合
查看>>
Centos7单网卡带VLAN多IP配置
查看>>
element-ui radio 再次点击取消选中
查看>>
hibernate9
查看>>
[LeetCode] String to Integer (atoi)
查看>>
vue组件参数校验与非props特性
查看>>
Socket与TCP,UDP
查看>>
java1环境与简介
查看>>
P3372 【模板】线段树 1 (区间查询)
查看>>
What Are You Talking About HDU - 1075(字典树)
查看>>
Phone List HDU - 1671(字典树)
查看>>