A100 正确使用递归和灵活使用if
来源:互联网 发布:二手软件app软件哪个好 编辑:程序博客网 时间:2024/06/05 07:45
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.
Subscribe to see which companies asked this question
public static boolean isSameTree(TreeNode p, TreeNode q) { if(p == null && q == null){ return true; }else if(p == null || q == null){//说明不可能都是null了 return false; }else if(p.val != q.val){//经过上两个说明都不为空了 return false; } boolean isSameTreeLeft = isSameTree(p.left, q.left); boolean isSameTreeRight = isSameTree(p.right, q.right); return isSameTreeLeft && isSameTreeRight;}
递归一定要找到合适的出口,只有p,q都不为空的时候再接着递归
0 0
- A100 正确使用递归和灵活使用if
- 正确使用ng-if和ng-show
- a100
- 灵活使用递归算法,生成Excel文件中的复合表头
- if和else if的使用注意事项
- 使用poi灵活生成和读取报表
- js和SpringMvc灵活使用cookie
- PHP学习第四节----控制语句if else 和递归的使用
- #if和#ifdef使用问题
- 正确配置和使用SQLmail
- 正确使用sizeof和strlen
- 正确实现和使用assert
- 灵活使用window.top
- ObjectDataSource+FormView灵活使用
- 灵活使用DataView
- Log4j 的灵活使用
- 灵活使用组策略!
- TRECT的灵活使用
- 计算机组成及其功能
- 大数
- 数字图像处理(1)- 透视变换
- uclinux很久前笔记11
- JsBridge最详细的解析,高版本webview的evaluateJavascript
- A100 正确使用递归和灵活使用if
- Hdu 5193 Go to movies Ⅱ(带删除数插入数的逆序数对,块状链表)
- OSGi - 第01章环境准备
- LibGdx文档译读(十三) AssetManager类
- python中__init__.py文件的作用
- Linux安装apue.3e(基于ubuntu12.0.4+centos6.8)
- uclinux很久前笔记12
- Linux操作命令符(基本)
- 18 UI美化自定义形状shape