Skip to content

Commit 8c37608

Browse files
author
钱毓婷
committed
feat: add solution of Same Tree(100) with javascript.
1 parent 1913e84 commit 8c37608

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
| [070][070-question] | [Climbing Stairs][070-tips] | [Easy][E] | [][070-java] | [][070-js] | [][070-kotlin] |
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-kotlin] |
76-
| [100][100-question] | [Same Tree][100-tips] | [Easy][E] | [][100-java] | | [][100-kotlin] |
76+
| [100][100-question] | [Same Tree][100-tips] | [Easy][E] | [][100-java] | [][100-js] | [][100-kotlin] |
7777
| [101][101-question] | [Symmetric Tree][101-tips] | [Easy][E] | [][101-java] | | [][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] |
@@ -378,6 +378,7 @@
378378
[069-js]: ./src/_069/Solution.js
379379
[070-js]: ./src/_070/Solution.js
380380
[083-js]: ./src/_083/Solution.js
381+
[100-js]: ./src/_100/Solution.js
381382
[226-js]: ./src/_226/Solution.js
382383
[561-js]: ./src/_561/Solution.js
383384
[643-js]: ./src/_643/Solution.js

src/_100/Solution.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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} p
10+
* @param {TreeNode} q
11+
* @return {boolean}
12+
*/
13+
var isSameTree = function(p, q) {
14+
if(p == null && q == null) return true
15+
if(p == null || q == null) return false
16+
if(p.val == q.val) {
17+
return isSameTree(p.left, q.left) && isSameTree(p.right, q.right)
18+
}
19+
return false
20+
};

tips/100/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,28 @@ class Solution {
8383
}
8484
```
8585

86+
```javascript
87+
/**
88+
* Definition for a binary tree node.
89+
* function TreeNode(val) {
90+
* this.val = val;
91+
* this.left = this.right = null;
92+
* }
93+
*/
94+
/**
95+
* @param {TreeNode} p
96+
* @param {TreeNode} q
97+
* @return {boolean}
98+
*/
99+
var isSameTree = function(p, q) {
100+
if(p == null && q == null) return true
101+
if(p == null || q == null) return false
102+
if(p.val == q.val) {
103+
return isSameTree(p.left, q.left) && isSameTree(p.right, q.right)
104+
}
105+
return false
106+
};
107+
```
86108
## 结语
87109

88110
如果你同我们一样热爱数据结构、算法、LeetCode,可以关注我们 GitHub 上的 LeetCode 题解:[LeetCode-Solution][ls]

0 commit comments

Comments
 (0)