List Cycle Time : Space : 1234567891011121314151617181920212223242526/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ListNode* Solution::detectCycle(ListNode* A) { ListNode* slow = A, *fast = A; while(fast->next and fast->next->next) { slow = slow->next; fast = fast->next->next; if(slow == fast) break; } if(fast->next and fast->next->next) { ListNode* runner = A; while(runner != slow) { slow = slow->next; runner = runner->next; } return runner; } return NULL;}