File tree Expand file tree Collapse file tree 1 file changed +7
-14
lines changed Expand file tree Collapse file tree 1 file changed +7
-14
lines changed Original file line number Diff line number Diff line change 1
1
/**
2
2
* 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)
6
7
* }
7
8
*/
8
9
/**
11
12
* @return {boolean }
12
13
*/
13
14
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 )
25
18
} ;
You can’t perform that action at this time.
0 commit comments