-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path141.py
29 lines (26 loc) · 824 Bytes
/
141.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#==================================================
#==> Title: linked-list-cycle
#==> Author: Zhang zhen
#==> Email: hustmatnoble.gmail.com
#==> GitHub: https://github.com/MatNoble
#==> Date: 1/14/2021
#==================================================
"""
https://leetcode-cn.com/problems/linked-list-cycle/
"""
# Definition for singly-linked list.
class ListNode:
def __init__(self, x):
self.val = x
self.next = None
class Solution:
def hasCycle(self, head: ListNode) -> bool:
if head == None:
return False
slow, fast = head, head
while fast != None and fast.next != None:
slow = slow.next
fast = fast.next.next
if slow == fast:
return True
return False