Leetcode 分享筆記

141. Linked List Cycle

題目

leetcode
b

python


class Solution(object):
    def hasCycle(self, head):
        """
        :type head: ListNode
        :rtype: bool
        """
        while head and head.next:
            if str(head.val) == "visited":
                return True
            head.val = "visited"
            head = head.next
        return False