LeetCide--Same Tree
来源:互联网 发布:sql注入原理及防范 编辑:程序博客网 时间:2024/05/30 20:07
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.
/** * 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==NULL && q==NULL) return true; if(q==NULL || p == NULL) return false; if(p->val != q->val) return false; bool left = isSameTree(p->left,q->left); bool right = isSameTree(p->right,q->right); return left&&right; }};
0 0
- LeetCide--Same Tree
- Same Tree
- Same Tree
- Same Tree
- Same Tree
- Same Tree
- Same Tree
- Same Tree
- Same Tree
- Same Tree
- Same Tree
- Same tree
- Same Tree
- Same Tree
- Same Tree
- Same Tree
- Same Tree
- Same Tree
- Intent和PendingIntent的区别
- Cocos2d-X3.0版的HelloWorld工程分析
- 2013年国家反腐案件
- Eclipse提高工作效率的好习惯
- spring ioc原理(看完后大家可以自己写一个spring)
- LeetCide--Same Tree
- 一个简单的基于内容的推荐算法
- 项目启动后,访问报 object is not an instance of declaring class 错误
- Big Nerd iOS Programming 第一、二章笔记
- [leetcode 105] Construct Binary Tree from Preorder and Inorder Traversal
- 制作动态及静态Framework
- 2015年国家反腐案件
- 2014年首个Linux内核更新发布 Linux 3.13提升了网络、内存性能
- linux 版本中 i386/i686/x86-64/pcc 等... 的区别