Easy-37
来源:互联网 发布:商业标书知乎 编辑:程序博客网 时间:2024/05/28 15:27
leetcode 100. 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.
AC:
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
bool isSameTree(struct TreeNode* p, struct TreeNode* q) {
if(p==NULL||q==NULL)
{
if(p==NULL&&q==NULL)
{
return true;
}
else
{
return false;
}
}
if(p->val!=q->val)
{
return false;
}
else
{
return isSameTree(p->left,q->left)&&isSameTree(p->right,q->right);
}
}
if(p==NULL||q==NULL)
{
if(p==NULL&&q==NULL)
{
return true;
}
else
{
return false;
}
}
if(p->val!=q->val)
{
return false;
}
else
{
return isSameTree(p->left,q->left)&&isSameTree(p->right,q->right);
}
}
tips: 很nice~
0 0
- Easy-37
- easy
- Easy
- Easy-题目37:111. Minimum Depth of Binary Tree
- Easy Plugs
- easy problem
- So Easy!
- so easy
- easy explorer
- Easy Explore
- Easy Task
- Easy Task
- Easy CHM
- HDU2699+Easy
- HDU4648+Easy
- Easy billiards
- Easy STL
- easy connect
- iOS-YHDownLoad
- 数据采集免费软件推荐:推荐一款免费的数据采集软件!
- 【贪心】洛谷 P1223 排队接水
- Android的JNI【实战教程】5⃣️---Android Studio 2.2 以上 NDK开发
- 搭建高可用mongodb集群(四)—— 分片
- Easy-37
- Android APK 瘦身
- 关于数据库的笔记
- 机器学习零基础?手把手教你用TensorFlow搭建图像识别系统(一)| 干货
- 百度地图JavaScript API 的运用
- 【分治】洛谷 P1226 取余运算||快速幂
- fastjson 与jackson 工具类封装
- 微信开发基础篇
- [poj1821] Fence DP单调队列优化