You are viewing a single comment's thread. Return to all comments →
This only worked with the first two test cases, I don't understand why it didn't work with the rest, could someone help me please?
bool exists(int tab[], int x, int n) { for (int i = 0; i < n; i++) { if (tab[i] == x) { return true; } } return false; } bool has_cycle(SinglyLinkedListNode* head) { SinglyLinkedListNode *pt; pt = head; int history[1000]; int i = 0; printf("hi"); while (pt != NULL) { if (exists(history, pt->data, i)) { return 1; } else { history[i] = pt->data; pt = pt->next; i++; } } return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
Cycle Detection
You are viewing a single comment's thread. Return to all comments →
This only worked with the first two test cases, I don't understand why it didn't work with the rest, could someone help me please?