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 77 * @see {@link https://en.wikipedia.org/wiki/Tree_(graph_theory)#Properties }
88 */
99export function diameterOfBinaryTree ( root ) {
10- let diameter = 0 ;
10+ let diameter = 0
1111
1212 function height ( node ) {
1313 if ( node === null ) {
14- return 0 ;
14+ return 0
1515 }
1616
17- const leftHeight = height ( node . left ) ;
18- const rightHeight = height ( node . right ) ;
17+ const leftHeight = height ( node . left )
18+ const rightHeight = height ( node . right )
1919
20- diameter = Math . max ( diameter , leftHeight + rightHeight ) ;
20+ diameter = Math . max ( diameter , leftHeight + rightHeight )
2121
22- return 1 + Math . max ( leftHeight , rightHeight ) ;
22+ return 1 + Math . max ( leftHeight , rightHeight )
2323 }
2424
25- height ( root ) ;
26- return diameter ;
25+ height ( root )
26+ return diameter
2727}
You can’t perform that action at this time.
0 commit comments