Easy 20 Same Tree(100)
来源:互联网 发布:python单行注释 编辑:程序博客网 时间:2024/05/10 22:55
Description
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.
Solution
深度优先遍历,左右子树和数据都要相同。
/** * Definition for a binary tree node. * 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||!q) { return (!p&&!q); }else{ return (p->val==q->val)&&isSameTree(p->left,q->left)&&isSameTree(p->right,q->right); } }};
0 0
- Easy 20 Same Tree(100)
- [Leetcode 100, easy] Same Tree
- 【LeetCode】(100)Same Tree(Easy)
- <LeetCode><Easy> 100 Same Tree
- LeetCode #100 - Same Tree - Easy
- leetcode 100 Same Tree(难易度:Easy)
- 100. Same Tree (Easy)
- 100. Same Tree [easy] (Python)
- 100. Same Tree 难度:easy
- 【leetcode】100. Same Tree(easy)
- LeetCode刷题(C++)——Same Tree(Easy)
- LeetCode(100) Same Tree
- Easy-题目7:100. Same Tree
- Leetcode 100. Same Tree (Easy) (cpp)
- LeetCode解题报告 100. Same Tree [easy]
- LeetCode-Easy刷题(19) Same Tree
- 【LeetCode】100.Same Tree(Easy)解题报告
- leetcode(java):100 Same Tree
- OpenStack安装与配置
- 动态规划为什么就是经典?
- BubbleSeekBar开源框架在andorid7.0无法适配的解决方案
- Node学习过程中遇到的一些小问题
- 使用Google的zxing组件识别二维码时,调整扫描区域和取景框的大小
- Easy 20 Same Tree(100)
- Android实现socket简单通讯总结
- mybatis自动生成代码git地址
- Spring AOP详解
- Java 网络编程时序问题
- 用深度学习解决大规模文本分类问题
- 去重是distinct还是group by?
- perl q qq qr qw qx 区别与使用方法
- 正则化理解