剑指 Offer 28. 对称的二叉树

https://leetcode-cn.com/problems/dui-cheng-de-er-cha-shu-lcof/

class Solution {
    public boolean isSymmetric(TreeNode root) {
        return root == null ? true : recur(root.left, root.right);
    }
    boolean recur(TreeNode L, TreeNode R){
		//如果两边都是空的,true
        if(L == null && R == null) return true;
		//任何一个不满足,false
        if(L == null || R == null || L.val != R.val) return false;
		//这一层满足,递归下一层
        return recur(L.left, R.right) && recur(L.right, R.left);
    }
}
上一篇:前端技巧--记忆


下一篇:二维数组的查找