剑指 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);
}
}
标签:right,return,recur,Offer,28,二叉树,TreeNode,null,root 来源: https://www.cnblogs.com/zhbeii/p/15531245.html