​160. Intersection of Two Linked Lists​

 code

/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
ListNode* a = headA;
ListNode* b = headB;
if(a==NULL || b==NULL) return NULL;//
while(a!=b)
{
a = a ? a->next : headB;
b = b ? b->next : headA;
}
return a;//err
}
};

Hash:

 

 

 

 

 

1. ​​Leetcode_Intersection of Two Linked Lists​​;