wecom-temp-1dcdd744347cc6ad3c15f1bf1f7c8c2a.png

    1. //传入头结点。
    2. +(Node *)findBeginning:(Node *)head{
    3. Node *slow = head;
    4. Node *fast = head;
    5. while (fast != nil && fast.next != nil) {
    6. slow = slow.next;
    7. fast = fast.next.next;
    8. if (slow == fast) {
    9. break;
    10. }
    11. }
    12. if (fast == nil || fast.next == nil) {
    13. return nil;
    14. }
    15. slow = head;
    16. while (slow != fast) {
    17. slow = slow.next;
    18. fast = fast.next;
    19. }
    20. return fast;
    21. }