0
点赞
收藏
分享

微信扫一扫

C语言 | Leetcode C语言题解之第141题环形链表

西风白羽 2024-06-17 阅读 25

题目:

题解:

bool hasCycle(struct ListNode* head) {
    if (head == NULL || head->next == NULL) {
        return false;
    }
    struct ListNode* slow = head;
    struct ListNode* fast = head->next;
    while (slow != fast) {
        if (fast == NULL || fast->next == NULL) {
            return false;
        }
        slow = slow->next;
        fast = fast->next->next;
    }
    return true;
}
举报

相关推荐

0 条评论