企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
![](https://box.kancloud.cn/8381d419e24ee83ea770f69735b4a442_1197x586.png) ~~~ /** * 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; } else { return isSame(root.left, root.right); } } private boolean isSame(TreeNode left, TreeNode right) { if (left == null && right == null) { return true; } if (left != null && right == null || left == null && right != null){ return false; } else { return left.val == right.val && isSame(left.left, right.right) && isSame(left.right, right.left); } } } ~~~