class Solution(object):
def hasCycle(self, head):
"""
:type head: ListNode
:rtype: bool
"""
cur = head
res = set()
while cur:
node = cur
if node not in res:
cur = cur.next
res.add(node)
else:
return True
return False
Leetcode-141环形链表
最新推荐文章于 2024-09-03 18:29:17 发布