fork download
  1. int len(Node *head){
  2. Node*temp = head;
  3. int count = 0;
  4. while (temp!=NULL){
  5. count++;
  6. temp = temp->next;
  7. }
  8. return count;
  9. }
  10. Node *intersectionOfTwoLinkedLists(Node *l1, Node *l2)
  11. {
  12. /Code here/
  13. int len1 = len(l1);
  14. int len2 = len(l2);
  15. Node *fast;
  16. Node *slow;
  17. int d;
  18. if(len1>len2){
  19. d = len1-len2;
  20. fast = l1;
  21. slow = l2;
  22. for(int i=0;i<d;i++){
  23. fast = fast->next;
  24. }
  25. }
  26. else{
  27. d = len2-len1;
  28. fast = l2;
  29. slow = l1;
  30. for(int i=0;i<d;i++){
  31. fast = fast->next;
  32. }
  33. }
  34.  
  35. while (slow != NULL && fast != NULL)
  36. {
  37. if (slow != fast)
  38. {
  39. slow = slow->next;
  40. fast = fast->next;
  41. continue;
  42. }
  43. return slow;
  44. }
  45. return NULL;
  46. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:9: error: ‘Node’ was not declared in this scope
 int len(Node *head){
         ^~~~
prog.cpp:1:15: error: ‘head’ was not declared in this scope
 int len(Node *head){
               ^~~~
prog.cpp:10:1: error: ‘Node’ does not name a type
 Node *intersectionOfTwoLinkedLists(Node *l1, Node *l2)
 ^~~~
stdout
Standard output is empty