Intersection of two LinkedList

I have written my code pls find it out idf the code is corect or not for the present situation

Node intersectionOfTwoLinkedLists(Node l1, Node l2) {
/* Code here */
Node one=l1.head;
Node two=l2.head;

    int delta=Math.abs(l1.size-l2.size);
    if(one.data<two.data){
        for(int i=0;i<delta;i++){
            two=two.next;
        }
    }else{
        for(int i=0;i<delta;i++){
            one=one.next;
        }
        while(one.data!=two.data){
            one=one.next;
            two=two.next;
        }
        return l1.data;
    }
}

}

try this approach :

Node intersectionOfTwoLinkedLists(Node l1, Node l2) {
    if (l1 == null || l2 == null)
        return null;

    Node a = l1;
    Node b = l2;

    while (a != b) {
        a = a == null ? l1 : a.next;
        b = b == null ? l2 : b.next;
    }

    return a;
}

im getting this ouput pls help

it basically means the element u r requesting does not exist.
always give input while compiling .Also try and check your loops if they are running for more times than needed

Im not getting answers i tried alot
pls help me

try to test it with input as
1 2 3 -1
4 2 3 -1

not the one given,
Consider these linked lists :
1 -> 2 -> 3 -> null
:arrow_upper_right:
4

(This is not the actual input that will be provided but rather a description of it)

Hope this helps :slight_smile:

could you pls provide more eleborative code
im saying again im not getting the output


here, this is the complete code
if this solves your doubt please mark it as resolved :slight_smile: