error
Intersection point of 2 ll
while(fast!=NULL&&fast->next!=NULL){
fast = fast->next;
slow = slow->next;
if(fast == slow){
return slow;
}
instead of this
do
while (slow != NULL && fast != NULL)
{
if (slow != fast)
{
slow = slow->next;
fast = fast->next;
continue;
}
return slow;
}
return NULL;
it is still giving error
int len(Node head){
Nodetemp = head;
int count = 0;
while (temp!=NULL){
count++;
temp = temp->next;
}
return count;
}
Node *intersectionOfTwoLinkedLists(Node *l1, Node *l2)
{
/Code here/
int len1 = len(l1);
int len2 = len(l2);
Node *fast;
Node *slow;
int d;
if(len1>len2){
d = len1-len2;
fast = l1;
slow = l2;
for(int i=0;i<d;i++){
fast = fast->next;
}
}
else{
d = len2-len1;
fast = l2;
slow = l1;
for(int i=0;i<d;i++){
fast = fast->next;
}
}
while (slow != NULL && fast != NULL)
{
if (slow != fast)
{
slow = slow->next;
fast = fast->next;
continue;
}
return slow;
}
return NULL;
}
please share code in cb ide
hard to debugthis way
TLE is coming in that code
