题解 | #判断二叉树是否对称#
判断二叉树是否对称
http://www.nowcoder.com/practice/1b0b7f371eae4204bc4a7570c84c2de1
import java.util.*;
/*
* public class TreeNode {
* int val = 0;
* TreeNode left = null;
* TreeNode right = null;
* }
*/
public class Solution {
/**
*
* @param root TreeNode类
* @return bool布尔型
*/
public boolean F2 (TreeNode root1,TreeNode root2){ //后序遍历
if(root1==null && root2==null) return true;
if(root1==null || root2==null) return false;
if(root1.val!=root2.val) return false;
return (F2(root1.left,root2.right)&&F2(root1.right,root2.left));
}
public boolean isSymmetric (TreeNode root) {
// write code here
if(root==null) return true;
return F2(root.left,root.right);
}
}