File tree 3 files changed +15
-15
lines changed
solution/0600-0699/0617.Merge Two Binary Trees
3 files changed +15
-15
lines changed Original file line number Diff line number Diff line change @@ -188,11 +188,11 @@ function mergeTrees(
188
188
root1 : TreeNode | null ,
189
189
root2 : TreeNode | null ,
190
190
): TreeNode | null {
191
- if (root1 == null && root2 == null ) return null ;
192
- if (root1 == null ) return root2 ;
193
- if (root2 == null ) return root1 ;
194
- let left = mergeTrees (root1 .left , root2 .left );
195
- let right = mergeTrees (root1 .right , root2 .right );
191
+ if (root1 === null && root2 = == null ) return null ;
192
+ if (root1 === null ) return root2 ;
193
+ if (root2 === null ) return root1 ;
194
+ const left = mergeTrees (root1 .left , root2 .left );
195
+ const right = mergeTrees (root1 .right , root2 .right );
196
196
return new TreeNode (root1 .val + root2 .val , left , right );
197
197
}
198
198
```
Original file line number Diff line number Diff line change @@ -169,11 +169,11 @@ function mergeTrees(
169
169
root1 : TreeNode | null ,
170
170
root2 : TreeNode | null ,
171
171
): TreeNode | null {
172
- if (root1 == null && root2 == null ) return null ;
173
- if (root1 == null ) return root2 ;
174
- if (root2 == null ) return root1 ;
175
- let left = mergeTrees (root1 .left , root2 .left );
176
- let right = mergeTrees (root1 .right , root2 .right );
172
+ if (root1 === null && root2 = == null ) return null ;
173
+ if (root1 === null ) return root2 ;
174
+ if (root2 === null ) return root1 ;
175
+ const left = mergeTrees (root1 .left , root2 .left );
176
+ const right = mergeTrees (root1 .right , root2 .right );
177
177
return new TreeNode (root1 .val + root2 .val , left , right );
178
178
}
179
179
```
Original file line number Diff line number Diff line change @@ -16,10 +16,10 @@ function mergeTrees(
16
16
root1 : TreeNode | null ,
17
17
root2 : TreeNode | null ,
18
18
) : TreeNode | null {
19
- if ( root1 == null && root2 == null ) return null ;
20
- if ( root1 == null ) return root2 ;
21
- if ( root2 == null ) return root1 ;
22
- let left = mergeTrees ( root1 . left , root2 . left ) ;
23
- let right = mergeTrees ( root1 . right , root2 . right ) ;
19
+ if ( root1 === null && root2 = == null ) return null ;
20
+ if ( root1 === null ) return root2 ;
21
+ if ( root2 === null ) return root1 ;
22
+ const left = mergeTrees ( root1 . left , root2 . left ) ;
23
+ const right = mergeTrees ( root1 . right , root2 . right ) ;
24
24
return new TreeNode ( root1 . val + root2 . val , left , right ) ;
25
25
}
You can’t perform that action at this time.
0 commit comments