leetcode 141. 环形链表 C语言版

xiaoxiao2025-10-14  8

给定一个链表,判断链表中是否有环。

bool hasCycle(struct ListNode *head) { struct ListNode *p = head,*q = head; if(p == NULL) return false; else { while(1) { if(p->next == NULL||p->next->next == NULL) return false; q = q->next; p = p->next->next; if(p == q) return true; } } }

 

转载请注明原文地址: https://www.6miu.com/read-5037909.html

最新回复(0)