File tree Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Original file line number Diff line number Diff line change 7
7
* @see {@link https://en.wikipedia.org/wiki/Tree_(graph_theory)#Properties }
8
8
*/
9
9
export function diameterOfBinaryTree ( root ) {
10
- let diameter = 0 ;
10
+ let diameter = 0
11
11
12
12
function height ( node ) {
13
13
if ( node === null ) {
14
- return 0 ;
14
+ return 0
15
15
}
16
16
17
- const leftHeight = height ( node . left ) ;
18
- const rightHeight = height ( node . right ) ;
17
+ const leftHeight = height ( node . left )
18
+ const rightHeight = height ( node . right )
19
19
20
- diameter = Math . max ( diameter , leftHeight + rightHeight ) ;
20
+ diameter = Math . max ( diameter , leftHeight + rightHeight )
21
21
22
- return 1 + Math . max ( leftHeight , rightHeight ) ;
22
+ return 1 + Math . max ( leftHeight , rightHeight )
23
23
}
24
24
25
- height ( root ) ;
26
- return diameter ;
25
+ height ( root )
26
+ return diameter
27
27
}
You can’t perform that action at this time.
0 commit comments