LeetCode--Same Tree
来源:互联网 发布:淘宝二级页面全屏代码 编辑:程序博客网 时间:2024/06/08 05:57
Same Tree
Total Accepted: 16072 Total Submissions: 38790My SubmissionsGiven 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.
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: bool isSameTree(TreeNode *p, TreeNode *q) { /* if(p->val==q->val && isSameTree(p->left,q->left) && isSameTree(p->right,q->right)) return true; else return false; */ //return isSameTree(p->left,q->left); //return isSameTree(p->right,q->right); if(p==NULL && q==NULL)return true;//两者都是NULL if(p!=NULL && q!=NULL && p->val==q->val//两者结点数据相等 && isSameTree(p->left,q->left) //且左子树相同 && isSameTree(p->right,q->right))//且右子树相同 return true; else return false; }};
0 0
- Leetcode - Tree - Same Tree
- [leetcode][tree] Same Tree
- LeetCode: Same Tree
- LeetCode Same Tree
- [Leetcode] Same Tree
- LeetCode : Same Tree
- [LeetCode] Same Tree
- leetcode 65: Same Tree
- Leetcode 100 Same Tree
- [leetcode] Same Tree
- [LeetCode]Same Tree
- [leetcode]Same Tree
- [Leetcode]Same Tree
- Leetcode: Same Tree
- [LeetCode] Same Tree
- LeetCode-Same Tree
- [leetcode] Same Tree
- LeetCode - Same Tree
- declspec(naked) 编写干净函数
- epoll使用详解(转)
- 一路走来,感谢所有!
- 2014-5.7,8,9,10,12
- 字节转换流ByteArrayOutputStreamout ,甚是好用,激动_成长...成长......在成长_百度空间 http://hi.baidu.com/yljf1314/item/06a5a
- LeetCode--Same Tree
- Shark0.9.0安装
- 使用Xcode修改iOS项目工程名和路径名
- Oracle创建表空间、创建用户、授权、授权对象的访问以及查看权限
- 12款界面精美的 HTML5 & CSS3 网站模板
- 坚持步行的惊人效果,网上被疯狂转载!
- .net 正则表达式应用
- android 布局如何支持多种不同屏幕尺寸
- 手游——卡通球