/*
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这题确实想偏了,以为要借助队列,然后一层一层判断


京公网安备 11010502036488号