判断二叉树是否对称
判断二叉树是否对称
http://www.nowcoder.com/questionTerminal/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 robot(TreeNode left,TreeNode right){ if(left==null && right==null){ return true; }else{ if(left==null || right==null){ return false; } } return left.val==right.val && robot(left.left,right.right) && robot(left.right,right.left); } public boolean isSymmetric(TreeNode root) { if(root==null){ return true; } return robot(root.left,root.right); } }