LeetCode141_环形链表

1. 题目

LeetCode141_环形链表
LeetCode141_环形链表

2. 题解

# 141
class TreeNode:
    def __init__(self, x):
        self.val = x
        self.next = None

class Solution:
    def hasCycle(self, head: TreeNode) -> bool:
        if head is None:
            return False

        slow = head
        fast = head
        while slow is not None and fast is not None:
            slow = slow.next
            fast = fast.next.next
            if slow == fast:
                return True
        return False
上一篇:leetcode-python-无重复字符的最长子串


下一篇:leetcode234.回文链表