public static int centerLength ( String s ) {
  int N = s . length ( ) ;
  if ( N % 2 == 0 ) {
    if ( s . charAt ( N / 2 ) != s . charAt ( N / 2 - 1 ) ) return 0 ;
    char center = s . charAt ( N / 2 ) ;
    int length = 2 ;
    int left = N / 2 - 2 , right = N / 2 + 1 ;
    while ( left >= 0 && s . charAt ( left ) == center && s . charAt ( right ) == center ) {
      left -- ;
      right ++ ;
      length += 2 ;
    }
    return length ;
  }
  else {
    char center = s . charAt ( N / 2 ) ;
    int left = N / 2 - 1 , right = N / 2 + 1 ;
    int length = 1 ;
    while ( left >= 0 && s . charAt ( left ) == center && s . charAt ( right ) == center ) {
      left -- ;
      right ++ ;
      length += 2 ;
    }
    return length ;
  }
}

public static int centerLength ( String s ) { int N = s . length ( ) ; if ( N % 2 == 0 ) { if ( s . charAt ( N / 2 ) != s . charAt ( N / 2 - 1 ) ) return 0 ; char center = s . charAt ( N / 2 ) ; int length = 2 ; int left = N / 2 - 2 , right = N / 2 + 1 ; while ( left >= 0 && s . charAt ( left ) == center && s . charAt ( right ) == center ) { left -- ; right ++ ; length += 2 ; } return length ; } else { char center = s . charAt ( N / 2 ) ; int left = N / 2 - 1 , right = N / 2 + 1 ; int length = 1 ; while ( left >= 0 && s . charAt ( left ) == center && s . charAt ( right ) == center ) { left -- ; right ++ ; length += 2 ; } return length ; } }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (decimal_integer_literal))) consequence: (block (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (decimal_integer_literal)))) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (decimal_integer_literal)))))) consequence: (return_statement (decimal_integer_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (decimal_integer_literal)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (decimal_integer_literal))) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (decimal_integer_literal)))) (while_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (identifier))) right: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (identifier)))) body: (block (expression_statement (update_expression (identifier))) (expression_statement (update_expression (identifier))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))))) (return_statement (identifier))) alternative: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (decimal_integer_literal)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (decimal_integer_literal))) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (while_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (identifier))) right: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (identifier)))) body: (block (expression_statement (update_expression (identifier))) (expression_statement (update_expression (identifier))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))))) (return_statement (identifier))))))