define hashset
HashSet < Node > hs = new HashSet < Node > ( ) ; while ( n1 != null ) { hs . Add ( n1 ) ; n1 = n1 . next ; } while ( n2 != null ) { if ( hs . Contains ( n2 ) ) { return n2 ; } n2 = n2 . next ; } return null ; } }