Leetcode 100 Same Tree 二叉树
就是判断两棵树的值和结构是否相同
注意:要判断是否所有的树节点是否为NULL
/**
* 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 true;
}
else if(!p||!q){
return false;
}
else{
if(p->val != q->val) return false;
else return isSameTree(p->left, q->left) &&
isSameTree(p->right, q->right);
}
}
};
Leetcode 100 Same Tree 二叉树的更多相关文章
- Leetcode 101 Symmetric Tree 二叉树
判断一棵树是否自对称 可以回忆我们做过的Leetcode 100 Same Tree 二叉树和Leetcode 226 Invert Binary Tree 二叉树 先可以将左子树进行Invert B ...
- LeetCode 100. Same Tree (判断树是否完全相同)
100. Same Tree Given two binary trees, write a function to check if they are the same or not. Two bi ...
- leetcode 100. Same Tree、101. Symmetric Tree
100. Same Tree class Solution { public: bool isSameTree(TreeNode* p, TreeNode* q) { if(p == NULL &am ...
- (二叉树 递归 DFS) leetcode 100. Same Tree
Given two binary trees, write a function to check if they are the same or not. Two binary trees are ...
- [LeetCode] 100. Same Tree ☆(两个二叉树是否相同)
描述 解析 根与根比较,左右子树互相递归比较即可. 代码 /** * Definition for a binary tree node. * public class TreeNode { * in ...
- LeetCode 100. Same Tree 判断两棵二叉树是否相等 C++
Given two binary trees, write a function to check if they are the same or not. Two binary trees are ...
- LeetCode 100. Same Tree (相同的树)
Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...
- [LeetCode] 100. Same Tree 相同树
Given two binary trees, write a function to check if they are the same or not. Two binary trees are ...
- leetcode 100. Same Tree
Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...
随机推荐
- 怎样自己构建一个小型的Zoomeye----从技术细节探讨到实现
转载请注明出处:viewmode=list">http://blog.csdn.net/u011721501?viewmode=list 0.概述 Zoomeye是个网络空间的搜 ...
- 搭建MHA问题汇总
1,Can't exec "mysqlbinlog": No such file or directory at /usr/share/perl5/vendor_perl/MHA/ ...
- mysql数据库 navicat premium mac 破解教程
https://www.jianshu.com/p/f3ef78deadaa 转自Navicat Premium for Mac v12.0.22.0 破解教程,macOS上手动破解,无需补丁,无毒 ...
- 【33.10%】【codeforces 604C】Alternative Thinking
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- IntelliJ IDEA设置鼠标悬浮提示
测试代码; public interface MyInterface { /** * 我是接口方法的注释 * @param num1 我是接口方法入参的注释 * @return 我是接口方法返回值的注 ...
- jquery修改获取radio的选中项
<input id="txtBeginDate" onclick="$('#divDate').css({'top':$('#txtBeginDate').offs ...
- Android的事件分发
1. Touch事件和绘制事件的异同之处 Touch事件和绘制事件非常相似,都是由ViewRoot派发下来的,可是不同之处在绘制事件是由应用中的某个View发起请求,一层一层上传到ViewRoot.再 ...
- 检测dll是32/64位?(直接读dll文件包含的某几个字节进行判断)
检查dll是32位还是64位? #include "stdafx.h" #include <Windows.h> int _tmain(int argc, _TCHAR ...
- [React] Public Class Fields with React Components
Public Class Fields allow you to add instance properties to the class definition with the assignment ...
- [Angular] Difference between ViewChild and ContentChild
*The children element which are located inside of its template of a component are called *view child ...