100. Same Tree
来源:互联网 发布:英文翻译什么软件好 编辑:程序博客网 时间:2024/06/07 08:55
题目原文
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.
思路
- 为空判断
- 若当前节点值相等且利用递归判断左子树与右子树均相等,则返回true,否则返回false
代码
class Solution {public: bool isSameTree(TreeNode* p, TreeNode* q) { if(!p&&!q) return true; else if(p&&!q) return false; else if(!p&&q) return false; else{ if((p->val)==(q->val)&&isSameTree(p->left,q->left)&&isSameTree(p->right,q->right)) return true; return false; } }};
0 0
- [LeetCode]100.Same Tree
- LeetCode 100. Same Tree
- 100.Same Tree
- 【LeetCode】100.Same Tree
- [Leetcode] 100. Same Tree
- [Leetcode] 100. Same Tree
- LeetCode --- 100. Same Tree
- LeetCode 100. Same Tree
- [leetcode] 100.Same Tree
- 100.Same Tree
- 100. Same Tree
- 100.Same Tree
- 100. Same Tree
- 100. Same Tree
- 100. Same Tree
- leetCode 100. Same Tree
- 100. Same Tree
- [LeetCode]100. Same Tree
- 21. Merge Two Sorted Lists
- ZJOI 2008 瞭望塔 半平面交
- Android API Guide for Media and Camera(一)—— 媒体与相机(媒体播放器)
- Ubuntu下mysql常用操作
- atom添加背景颜色
- 100. Same Tree
- 指针和数组
- 106. Construct Binary Tree from Inorder and Postorder Traversal
- AWS坑
- Spring注解
- jstl标签库
- 定时器技术选型の不同业务背景(二)
- Hello World!
- 怎么标识一个dao