Skip to content

Commit 50250dc

Browse files
authored
Create intersect_linkedlist.cpp
find the point of intersection of two linked lists ; time complexity O(n^2);
1 parent 3684244 commit 50250dc

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

intersect_linkedlist.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
class Solution {
2+
public:
3+
ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
4+
ListNode*first=headA;
5+
ListNode*second=headB;
6+
ListNode*internode;
7+
int flag;
8+
9+
while(first!=NULL){
10+
second=headB;
11+
while(second!=NULL){
12+
if(&first==&second){
13+
flag=1;
14+
internode=first;
15+
}
16+
else{
17+
flag=0;
18+
}
19+
second=second->next;
20+
21+
}
22+
first=first->next;
23+
24+
25+
}
26+
if(flag==1){
27+
return internode;
28+
}
29+
else{
30+
return NULL;
31+
32+
}
33+
34+
}
35+
};

0 commit comments

Comments
 (0)