NC_16_IS_Symmetric
package org.example.interview.practice; /** * @author xianzhe.ma * @date 2021/8/15 */ public class NC_16_IS_Symmetric { public boolean isSymmetric (TreeNode root) { if(root == null) return true; return check(root.left,root.right); } public boolean check(TreeNode left, TreeNode right){ if(left == null && right == null) return true; if(left == null || right == null) return false; return left.val == right.val && check(left.left,right.right) && check(left.right,right.left); } public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; } }