【LeetCode】141. 环形链表

leetcode题目链接 141. 环形链表
【LeetCode】141. 环形链表_第1张图片

#include 
#include 

struct ListNode {
    int val;
    struct ListNode* next;
};
typedef struct ListNode ListNode;

bool hasCycle(ListNode* head) {
    ListNode* slow = head, * fast = head;
    while (fast && fast->next) {
        slow = slow->next;
        fast = fast->next->next;
        if (slow == fast) {
            return true;
        }
    }
    return false;
}   

你可能感兴趣的:(leetcode,链表,算法,数据结构,c语言)