Skip to content

Commit 475d73f

Browse files
author
QianYuTing
committed
add the solution of Symmetric Tree(101) with Javascript.
1 parent f15a8f3 commit 475d73f

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
| [083][083-question] | [Remove Duplicates from Sorted List][083-tips] | [Easy][E] | [][083-java] | [][083-js] | [][083-kotlin] |
7575
| [088][088-question] | [Merge Sorted Array][088-tips] | [Easy][E] | [][088-java] | [][088-js] | [][088-kotlin] |
7676
| [100][100-question] | [Same Tree][100-tips] | [Easy][E] | [][100-java] | [][100-js] | [][100-kotlin] |
77-
| [101][101-question] | [Symmetric Tree][101-tips] | [Easy][E] | [][101-java] | | [][101-kotlin] |
77+
| [101][101-question] | [Symmetric Tree][101-tips] | [Easy][E] | [][101-java] | [][101-js] | [][101-kotlin] |
7878
| [104][104-question] | [Maximum Depth of Binary Tree][104-tips] | [Easy][E] | [][104-java] | | [][104-kotlin] |
7979
| [107][107-question] | [Binary Tree Level Order Traversal II][107-tips] | [Easy][E] | [][107-java] | | [][107-kotlin] |
8080
| [108][108-question] | [Convert Sorted Array to Binary Search Tree][108-tips] | [Easy][E] | [][108-java] | | [][108-kotlin] |
@@ -454,6 +454,7 @@ commit信息模板: ``feat: add the solution of `Two Sum`(001) with Java``
454454
[083-js]: ./src/_083/Solution.js
455455
[088-js]: ./src/_088/Solution.js
456456
[100-js]: ./src/_100/Solution.js
457+
[101-js]: ./src/_101/Solution.js
457458
[226-js]: ./src/_226/Solution.js
458459
[561-js]: ./src/_561/Solution.js
459460
[643-js]: ./src/_643/Solution.js

src/_101/Solution.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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 == null) return true
14+
var x = function(left, right) {
15+
if(left == null && right == null) return true
16+
if(left == null || right == null) return false
17+
if (left.val !== right.val) return false;
18+
return x(left.left, right.right) && x(left.right, right.left)
19+
}
20+
return x(root.left, root.right)
21+
};

0 commit comments

Comments
 (0)