so easy~~~
怪不得看到后面那位同学天天刷这个oj,O(∩_∩)O哈哈~
不过还是记录一下吧。。。
/**
* Definition for binary tree
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public boolean isSameTree(TreeNode p, TreeNode q) {
if((p == null && q != null) || (p != null && q == null)){
return false;
}
else if(p == null && q == null){
return true;
}
else{
if((p.val == q.val) && isSameTree(p.left, q.left) && isSameTree(p.right, q.right)){
return true;
}
else{
return false;
}
}
}
}