游客,本帖隐藏的内容需要积分高于 40 才可浏览,您当前积分为 0
- # Definition for singly-linked list.
- # class ListNode:
- # def __init__(self, x):
- # self.val = x
- # self.next = None
- class Solution:
- def hasCycle(self, head: Optional[ListNode]) -> bool:
- try:
- for _ in range(10_001):
- head = head.next
- return True
- except:
- return False
复制代码
https://leetcode.com/problems/linked-list-cycle/ |