fork download
  1. ListNode* FindNode(ListNode* head, int N) {
  2. /*Write your code here.
  3. *Don't write main().
  4. *Don't take input, it is passed as function argument.
  5. *Don't print output.
  6. *Taking input and printing output is handled automatically.
  7. */
  8. bool cycle = 0;
  9. ListNode*slow = head;
  10. ListNode*fast = head;
  11. ListNode*temp = NULL;
  12. ListNode*k = NULL;
  13. if(fast == NULL && fast->next == NULL){
  14. return NULL;
  15. }
  16. while(fast != NULL && fast->next != NULL){
  17. fast = fast->next->next;
  18. slow = slow->next;
  19. if(fast == NULL && fast->next == NULL){
  20. return NULL;
  21. }
  22. if(slow == fast){
  23. slow = head;
  24. temp = fast;
  25. }
  26. while(temp->next!=slow->next){
  27. temp = temp->next;
  28. slow = slow->next;
  29. }
  30. k = slow->next;
  31. bool cycle = 1;
  32. }
  33. if(cycle == 1){
  34. ListNode*slow1 = head;
  35. ListNode*fast1 = head;
  36. for(int i=1;i<N;i++){
  37. fast1 = fast1->next;
  38. }
  39. while(fast1!=k && fast1->next!=k){
  40. fast1 = fast1->next;
  41. slow1 = slow1->next;
  42. }
  43. return slow1;
  44. }
  45. else{
  46. return NULL;
  47. }
  48.  
  49. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:1: error: ‘ListNode’ does not name a type
 ListNode* FindNode(ListNode* head, int N) {
 ^~~~~~~~
stdout
Standard output is empty