Whats wrong with my code

your logic is correct, but you just messed up with the variables and scope things in java.
your class Node() has a constructor … there is a error in first line… it should be
this.data = data;

Now your class merge has a static variable head and static variables are shared among all objects of class, so list1.head and list2.head are same, which is a problem here.

try to fix these things and let me know if you still stuck.
thanks

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.