Skip to content

Commit 72ba1b9

Browse files
authored
Update 100-same-tree.js
1 parent 4235e28 commit 72ba1b9

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

100-same-tree.js

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/**
22
* Definition for a binary tree node.
3-
* function TreeNode(val) {
4-
* this.val = val;
5-
* this.left = this.right = null;
3+
* function TreeNode(val, left, right) {
4+
* this.val = (val===undefined ? 0 : val)
5+
* this.left = (left===undefined ? null : left)
6+
* this.right = (right===undefined ? null : right)
67
* }
78
*/
89
/**
@@ -11,15 +12,7 @@
1112
* @return {boolean}
1213
*/
1314
const isSameTree = function(p, q) {
14-
return isSame(p, q);
15-
};
16-
17-
const isSame = (p, q) => {
18-
if (p === null && q === null) return true;
19-
20-
if ((p !== null && q === null) || (p === null && q !== null)) return false;
21-
22-
if (p.val !== q.val) return false;
23-
24-
return isSame(p.left, q.left) && isSame(p.right, q.right);
15+
if(p == null && q == null) return true
16+
if(p == null || q == null || p.val !== q.val) return false
17+
return isSameTree(p.left, q.left) && isSameTree(p.right, q.right)
2518
};

0 commit comments

Comments
 (0)