MCPcopy Create free account
hub / github.com/HuberTRoy/leetCode / Solution

Class Solution

Array/LinkedListCycle.py:31–65  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29# self.next = None
30
31class Solution(object):
32 def hasCycle(self, head):
33 """
34 :type head: ListNode
35 :rtype: bool
36 """
37
38 # while head:
39 # if hasattr(head, 'hasVisited'):
40 # return True
41
42 # head.hasVisited = True
43 # head = head.next
44 # return False
45
46 if not head:
47 return False
48
49 two_head = head.next
50
51 if not two_head:
52 return False
53
54 while head != None and two_head != None:
55
56 if head == two_head:
57 return True
58
59 head = head.next
60 try:
61 two_head = two_head.next.next
62 except:
63 return False
64
65 return False
66

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected