We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No description provided.
The text was updated successfully, but these errors were encountered:
给你一个二叉树的根节点 root , 检查它是否轴对称。 输入:root = [1,2,2,3,4,4,3] 输出:true
const isSymmetric = (root) => { const check = (left, right) => { if (left == null && right == null) { // 两个子树都为null,是对称的 return true; } if (left && right) { // 两个子树都存在,则需要:root值相同,且他们的子树也满足镜像 return left.val == right.val && check(left.left, right.right) && check(left.right, right.left); } return false; // 一个子树存在一个不存在,肯定不对称 }; if (root == null) { // 如果传入的root就是null,对称 return true; } return check(root.left, root.right); // 否则,判断它的左右子树是否满足对称 };
Sorry, something went wrong.
No branches or pull requests
No description provided.
The text was updated successfully, but these errors were encountered: