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

public class Solution {
public boolean isSameTree(TreeNode p, TreeNode q) {
if( p == null && q == null){
return true;
}
else if(p == null && q != null){
return false;
}
else if(q == null && p != null){
return false;
}
else if( p.val == q.val){
if(isSameTree(p.left, q.left) == true && isSameTree(p.right, q.right) == true){
return true;
}
else{
return false;
}
}
else{
return false;
}
}
}
discuss中的更优解

public boolean isSameTree(TreeNode p, TreeNode q) {
if(p == null && q == null) return true;
if(p == null || q == null) return false;<span style="white-space:pre">	</span>//此处合并了我第2、3个else if
return p.val == q.val && isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
}

#### LeetCode(100)Same Tree

2014-01-09 06:41:21

#### 100. Same Tree Leetcode Python

2015-01-15 23:33:34

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

2014-04-01 20:22:21

#### [LeetCode-100]Same Tree(java)

2016-10-08 20:48:41

#### 【LeetCode】100. Same Tree 解题报告

2016-05-30 22:06:42

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

2016-05-13 22:13:29

#### 【leetcode c++】100 Same Tree

2015-07-27 14:34:06

#### LeetCode-Same Tree(java)

2014-05-14 09:56:06

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

2017-04-20 00:34:36

#### LeetCode 100 Same Tree(Python详解及实现)

2017-08-11 16:52:26

## 不良信息举报

Leetcode 100. Same Tree