static int length ( Node node ) {
  if ( node == null ) return 0 ;
  int left = length ( node . left ) ;
  int right = length ( node . right ) ;
  int Leftmax = 0 , Rightmax = 0 ;
  if ( node . left != null && node . left . val == node . val ) Leftmax += left + 1 ;
  if ( node . right != null && node . right . val == node . val ) Rightmax += right + 1 ;
  ans = Math . max ( ans , Leftmax + Rightmax ) ;
  return Math . max ( Leftmax , Rightmax ) ;
}

static int length ( Node node ) { if ( node == null ) return 0 ; int left = length ( node . left ) ; int right = length ( node . right ) ; int Leftmax = 0 , Rightmax = 0 ; if ( node . left != null && node . left . val == node . val ) Leftmax += left + 1 ; if ( node . right != null && node . right . val == node . val ) Rightmax += right + 1 ; ans = Math . max ( ans , Leftmax + Rightmax ) ; return Math . max ( Leftmax , Rightmax ) ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier))) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (null_literal))) consequence: (return_statement (decimal_integer_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation name: (identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation name: (identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (field_access object: (identifier) field: (identifier)) right: (null_literal)) right: (binary_expression left: (field_access object: (field_access object: (identifier) field: (identifier)) field: (identifier)) right: (field_access object: (identifier) field: (identifier))))) consequence: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal))))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (field_access object: (identifier) field: (identifier)) right: (null_literal)) right: (binary_expression left: (field_access object: (field_access object: (identifier) field: (identifier)) field: (identifier)) right: (field_access object: (identifier) field: (identifier))))) consequence: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (identifier) right: (identifier)))))) (return_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier))))))