Time: 68 ms (33.08%), Space: 21.4 MB (5.90%) - LeetHub

This commit is contained in:
Deven
2022-05-07 15:57:18 -04:00
parent 163f5e22c7
commit a3c8d9f5c8
@@ -0,0 +1,22 @@
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution(object):
def hasCycle(self, head):
"""
:type head: ListNode
:rtype: bool
"""
if head == None or head.next == None: return False
myDict = {head: 0}
point = head
while True:
point = point.next
if point == None: return False
if myDict.get(point) == None:
myDict[point] = 0
else:
return True