3.30 二叉树的题,反正递归是很好用的
至于其他的方法,现在并不想仔细研究。
呵呵
/**
* Definition of TreeNode:
* public class TreeNode {
* public int val;
* public TreeNode left, right;
* public TreeNode(int val) {
* this.val = val;
* this.left = this.right = null;
* }
* }
*/
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) {
if( a == null && b == null){
return true;// Write your code here
}
if( a != null && b != null){
if(a.val == b.val){
if(isIdentical(a.left,b.left)){
return isIdentical(a.right,b.right);
}
else
return false;
}
}
return false;
}
}