private static long findSolution ( int [ ] nums ) {
  long [ ] prevValues = new long [ 2 ] ;
  int prevPointer = 0 ;
  long count = 0 ;
  int precedingCount = 0 ;
  for ( int i = 0 ;
  i < nums . length ;
  i ++ ) {
    int val = nums [ i ] ;
    if ( val > 0 ) {
      precedingCount ++ ;
      count += prevValues [ prevPointer ] ;
      continue ;
    }
    long thisCount = 1 + precedingCount + prevValues [ ( prevPointer + 1 ) % 2 ] ;
    count += thisCount ;
    precedingCount = 0 ;
    prevValues [ ( prevPointer + 1 ) % 2 ] = thisCount ;
    prevPointer = ( prevPointer + 1 ) % 2 ;
  }
  return count ;
}

private static long findSolution ( int [ ] nums ) { long [ ] prevValues = new long [ 2 ] ; int prevPointer = 0 ; long count = 0 ; int precedingCount = 0 ; for ( int i = 0 ; i < nums . length ; i ++ ) { int val = nums [ i ] ; if ( val > 0 ) { precedingCount ++ ; count += prevValues [ prevPointer ] ; continue ; } long thisCount = 1 + precedingCount + prevValues [ ( prevPointer + 1 ) % 2 ] ; count += thisCount ; precedingCount = 0 ; prevValues [ ( prevPointer + 1 ) % 2 ] = thisCount ; prevPointer = ( prevPointer + 1 ) % 2 ; } return count ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (integral_type) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (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: (decimal_integer_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (field_access object: (identifier) field: (identifier))) update: (update_expression (identifier)) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (array_access array: (identifier) index: (identifier)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (expression_statement (update_expression (identifier))) (expression_statement (assignment_expression left: (identifier) right: (array_access array: (identifier) index: (identifier)))) (continue_statement))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (binary_expression left: (decimal_integer_literal) right: (identifier)) right: (array_access array: (identifier) index: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (decimal_integer_literal)))))) (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (decimal_integer_literal))) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (decimal_integer_literal)))))) (return_statement (identifier))))