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

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

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.

题目含义:判断两个二进制树结构是否相等

1     public boolean sameTree(TreeNode p, TreeNode q) 2     { 3         if (p==null && q==null) return true; 4         if (p==null || q==null) return false; 5         if (p.val != q.val) return false; 6         return sameTree(p.left,q.left) && sameTree(p.right,q.right); 7     }  8     public boolean isSameTree(TreeNode p, TreeNode q) { 9         return sameTree(p,q);        10     }

 

转载于:https://www.cnblogs.com/wzj4858/p/7705259.html

你可能感兴趣的文章
centos7: iptables保存(配置完nginx的web规则后)
查看>>
Windows下openssl的下载安装和使用
查看>>
[LeetCode] Dungeon Game
查看>>
人工智能搜素策略
查看>>
Servlet简要介绍及入门案例。
查看>>
IDEA 控制台中文乱码
查看>>
千牛卖家工作平台使用教程
查看>>
能被3整除的数(白学了)
查看>>
1161 - Extreme GCD
查看>>
使用Doxyen和Graghviz为自己的库快速做个文档
查看>>
关系型数据库和非关系型数据库
查看>>
2013年11月15日
查看>>
Android5.0Demo
查看>>
c++ UDP套接字客服端代码示范
查看>>
python中的关键字---1(基础数据类)
查看>>
《windows程序设计》文本输出(03)
查看>>
虚拟机、容器与Docker
查看>>
波兰表达式
查看>>
总结一下几个for循环常见用法和区别
查看>>
LNMP安装目录及配置文件位置
查看>>