# leetcode 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.

Subscribe to see which companies asked this question

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

#### LeetCode(100)Same Tree

2014-01-09 06:41:21

#### 100. Same Tree [easy] (Python)

2016-05-13 22:13:29

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

2014-04-01 20:22:21

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

2017-04-20 00:34:36

#### 关于Leetcode中Same Tree一题的理解

2016-08-21 20:41:34

#### LeetCode-Same Tree(java)

2014-05-14 09:56:06

#### Same Tree -- LeetCode

2014-04-03 04:07:01

#### LeetCode 100: Same Tree

2015-03-31 21:20:21

#### Leetcode #100 Same tree

2015-12-01 16:39:17

#### leetcode || 100、Same Tree

2015-04-17 17:21:55