判断对称二叉树 (判断对称二叉树)

 

思路:

// @Title: 判断对称二叉树 (判断对称二叉树)
// @Author: qisiii
// @Date: 2022-02-20 22:44:35
// @Runtime: 0 ms
// @Memory: 39.3 MB
// @comment: 
// @flag: 
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
class Solution {
    public boolean isSymmetric(TreeNode root) {
        if(root==null)return true;
        return isJing(root.left,root.right);

    }
    public boolean isJing(TreeNode left,TreeNode right){
        if(left==null&&right==null){
            return true;
        }
        if(left==null||right==null){
            return false;
        }
        return left.val==right.val&&isJing(left.left,right.right)&&isJing(left.right,right.left);
    }
}
Licensed under CC BY-NC-SA 4.0
最后更新于 2024-10-18