力扣:160. 相交链表
作者:互联网
1、暴力解
/**
* 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* cru;
while(headA!=NULL)
{
cru=headB;
while(cru!=NULL)
{
if(headA==cru) return headA;
cru=cru->next;
}
headA=headA->next;
}
return NULL;
}
};
标签:力扣,ListNode,cru,int,next,链表,headA,NULL,160 来源: https://blog.csdn.net/qq_50917103/article/details/121186399