static int getIntesectionNode ( Node head1 , Node head2 ) {
  Node current1 = head1 ;
  Node current2 = head2 ;
  if ( current1 == null || current2 == null ) return - 1 ;
  while ( current1 != null && current2 != null && current1 != current2 ) {
    current1 = current1 . next ;
    current2 = current2 . next ;
    if ( current1 == current2 ) return current1 . data ;
    if ( current1 == null ) current1 = head2 ;
    if ( current2 == null ) current2 = head1 ;
  }
  return current1 . data ;
}

static int getIntesectionNode ( Node head1 , Node head2 ) { Node current1 = head1 ; Node current2 = head2 ; if ( current1 == null || current2 == null ) return - 1 ; while ( current1 != null && current2 != null && current1 != current2 ) { current1 = current1 . next ; current2 = current2 . next ; if ( current1 == current2 ) return current1 . data ; if ( current1 == null ) current1 = head2 ; if ( current2 == null ) current2 = head1 ; } return current1 . data ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier)) (formal_parameter type: (type_identifier) name: (identifier))) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (identifier))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (identifier))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (null_literal)) right: (binary_expression left: (identifier) right: (null_literal)))) consequence: (return_statement (unary_expression operand: (decimal_integer_literal)))) (while_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (binary_expression left: (identifier) right: (null_literal)) right: (binary_expression left: (identifier) right: (null_literal))) right: (binary_expression left: (identifier) right: (identifier)))) body: (block (expression_statement (assignment_expression left: (identifier) right: (field_access object: (identifier) field: (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (field_access object: (identifier) field: (identifier)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (return_statement (field_access object: (identifier) field: (identifier)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (null_literal))) consequence: (expression_statement (assignment_expression left: (identifier) right: (identifier)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (null_literal))) consequence: (expression_statement (assignment_expression left: (identifier) right: (identifier)))))) (return_statement (field_access object: (identifier) field: (identifier)))))