题解 | #对称的二叉树#
对称的二叉树
http://www.nowcoder.com/practice/ff05d44dfdb04e1d83bdbdab320efbcb
/* public class TreeNode { public int val; public TreeNode left; public TreeNode right; public TreeNode (int x) { val = x; } }*/ class Solution { public bool isSymmetrical(TreeNode pRoot) { // write code here return IsSame(pRoot, pRoot); } public bool IsSame(TreeNode L,TreeNode R) { if(L==null && R==null) return true; if(L==null || R==null) return false; return L.val==R.val && IsSame(L.left, R.right) && IsSame(L.right, R.left); } }z这题确实想偏了,以为要借助队列,然后一层一层判断