| 29 | # self.next = None |
| 30 | |
| 31 | class 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 |
nothing calls this directly
no outgoing calls
no test coverage detected