/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public boolean isSymmetric(TreeNode root) {
if(root == null) return true;
return helper(root, root.left, root.right);
}
private boolean helper(TreeNode root, TreeNode p, TreeNode q){
if(p == null && q == null){
return true;
}
if(p == null || q == null){
return false;
}
if(p.val != q.val){
return false;
}
return helper(root, p.left, q.right) && helper(root, p.right, q.left);
}
}
[LeetCode] 98. Validate Binary Search Tree
最新推荐文章于 2022-08-20 21:51:38 发布