import { ListNode } from './LinkList' ; param { ListNode } phead1 param { ListNode } phead2 return { ListNode } function FirstSameNode ( phead1 , phead2 ) { let len1 = GetListLength ( phead1 ) ; let len2 = GetListLength ( phead2 ) ; let diff = Math . abs ( len1 - len2 ) ; let longHead , shortHead ; if ( len1 > len2 ) { longHead = phead1 ; shortHead = phead2 ; } else { longHead = phead2 ; shortHead = phead1 ; } for ( let i = 0 ; i < diff ; i ++ ) { longHead = longHead . next ; } while ( longHead !== null && shortHead !== null && longHead . val !== shortHead . val ) { longHead = longHead . next ; shortHead = shortHead . next ; } let result = longHead ; return result ; } param { ListNode } phead return { number } function GetListLength ( phead ) { let num = 0 ; while ( phead . next ) { num ++ ; phead = phead . next ; } return num ; } export { FirstSameNode } ;