您的位置:首页 > Web前端

LintCode-剑指Offer-(380)两个链表的交叉

2015-11-29 17:01 363 查看
/**
* Definition for singly-linked list.
* struct ListNode {
*     int val;
*     ListNode *next;
*     ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
/**
* @param headA: the first list
* @param headB: the second list
* @return: a ListNode
*/
ListNode *getIntersectionNode(ListNode *headA,ListNode *headB) {
// write your code here
ListNode* tmpb = headB;
ListNode* tmpa = headA;
while (tmpa!=NULL){
tmpb = headB;
while (tmpb!=NULL){
if (tmpa->val!=tmpb->val){
tmpb = tmpb->next;;
}
else{
return tmpa;
}
}
tmpa = tmpa->next;
}
return NULL;
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  LintCode