Time: 56 ms (60.19%), Space: 21.4 MB (5.54%) - LeetHub

This commit is contained in:
Deven
2023-01-08 09:25:46 -05:00
parent 066f833e83
commit 006c92405b
@@ -0,0 +1,25 @@
# 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 point != None:
point = point.next
if myDict.get(point) == None:
myDict[point] = 0
else:
return True
return False