Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 160ec6d

Browse files
committed
feat: 对称二叉树
1 parent 81cad5f commit 160ec6d

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

二叉树/对称二叉树-101.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* function TreeNode(val) {
4+
* this.val = val;
5+
* this.left = this.right = null;
6+
* }
7+
*/
8+
/**
9+
* @param {TreeNode} root
10+
* @return {boolean}
11+
*/
12+
var isSymmetric = function (root) {
13+
if (!root) return true
14+
let helper = (left, right) => {
15+
if (!left && !right) {
16+
return true
17+
}
18+
if (!left || !right) {
19+
return false
20+
}
21+
if (left.val === right.val) {
22+
return helper(left.left, right.right) && helper(left.right, right.left)
23+
} else {
24+
return false
25+
}
26+
}
27+
return helper(root, root)
28+
}

0 commit comments

Comments
 (0)