141:环形链表


class Solution(object):
    def hasCycle(self, head):
        """
        :type head: ListNode
        :rtype: bool
        """
        ans=[]
        while head:
            if head in ans:
                return True
            ans.append(head)
            head=head.next
        return False
上一篇:精选50题之 141. 环形链表


下一篇:LeetCode-141-环形链表