Identical Binary Tree
题目:
Check if two binary trees are identical. Identical means the two binary trees have the same structure and every identical position has the same value.
分析:
想通了的话1分钟就可以做完
解法:
public class Solution {
/**
* @param a, b, the root of binary trees.
* @return true if they are identical, or false.
*/
public boolean isIdentical(TreeNode a, TreeNode b) {
// Write your code here
if (a == null && b == null) {
return true;
}
if (a == null || b == null) {
return false;
}
return a.val == b.val && isIdentical(a.left, b.left) && isIdentical(a.right, b.right);
}
}