mirror of
https://github.com/devenperez/leetcode.git
synced 2026-06-13 14:57:08 +00:00
25 lines
611 B
Python
25 lines
611 B
Python
# 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 |