Checks if current node is not null and doesn 't have any children
if ( root . children != null && root . children . length == 0 ) { ans = Math . max ( ans , root . val ) ; return [ root . val , 1 ] ; }