LeetCode 第101题 对称二叉树
程序员文章站
2024-01-11 11:53:46
...
/**
* 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) {
return isSymmetricTree(root, root);
}
public boolean isSymmetricTree(TreeNode t1, TreeNode t2) {
if (t1 == null && t2 == null) return true;
if (t1 == null || t2 == null) return false;
return (t1.val == t2.val)&& isSymmetricTree(t1.right, t2.left)&& isSymmetricTree(t1.left, t2.right);
}
}
上一篇: Vue.js中多页面项目如何配置
推荐阅读