对称的二叉树

题目

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

解法

1
2
3
4
5
6
7
8
9
public boolean isSymmetric(TreeNode root) {
return root == null ? true : recur(root.left, root.right);
}

boolean recur(TreeNode L, TreeNode R) {
if (L == null && R == null) return true;
if (L == null || R == null || L.val != R.val) return false;
return recur(L.left, R.right) && recur(L.right, R.left);
}
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×