LeetCode-101-对称二叉树
思路
一棵树,判断左右节点是否满足对称,以及左右节点的左左右右,左右右左
代码
class Solution {
public boolean isSymmetric(TreeNode root) {
if(root==null)return true;
return helper(root.left,root.right);
}
public boolean helper(TreeNode L,TreeNode R){
if(L==null&&R==null)return true;
if(L==null||R==null)return false;
return (L.val==R.val)&&helper(L.left,R.right)&&helper(L.right,R.left);
}
}