Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- knakul853
- */
- class Solution {
- public:
- // one more solution could be to use the lenght and after travel equal lenght...travel all pointers // together
- ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
- ListNode* a = headA;
- ListNode* b = headB;
- // let A travels a+c (c is the common distance ) and B travels b+c
- // after assigning the pointers to the other side bothe tarvels a+b+2*c
- while( a!= b )
- {
- a = a == NULL ? headB : a->next;
- b = b == NULL ? headA : b->next;
- }
- return a;
- }
- };
Add Comment
Please, Sign In to add comment