# 100. Same Tree

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 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==NULL&&q==NULL)
return true;
if(p==NULL)
return false;
if(q==NULL)
return false;
if(p->val!=q->val)
return false;
bool t1,t2;
t1=isSameTree(p->left,q->left);
t2=isSameTree(p->right,q->right);
if(t1==false||t2==false)
return false;
return true;
}
};

#### LeetCode(100)Same Tree

2014-01-09 06:41:21

#### LeetCode 100 — Same Tree（C++ Java Python）

2014-04-01 20:22:21

#### LeetCode-Same Tree(java)

2014-05-14 09:56:06

#### 100. Same Tree 树是否相同

2016-06-27 09:56:20

#### [LeetCode]100. Same Tree(相同树)

2017-04-20 00:34:36

#### [leetcode-100]Same Tree(C)

2015-08-11 10:32:20

#### 100. Same Tree（二叉树、递归）

2018-02-27 23:06:00

#### 100. Same Tree Leetcode Python

2015-01-15 23:33:34

#### Leetcode#100. Same Tree(判断两个二叉树相同)

2017-09-27 12:29:08