首页 > 代码库 > 【leetcode】Linked List Cycle (python)

【leetcode】Linked List Cycle (python)

class Solution:
    # @param head, a ListNode
    # @return a boolean
    def hasCycle(self, head):
        if None == head or None == head.next:
            return False
        pfast = head
        pslow = head
        while pfast and pfast.next:
            pfast = pfast.next.next
            pslow = pslow.next
            if pfast == pslow:
                return True
        return False
        
这个题是很经典的题,要我说什么,我也说不出什么,只是觉得这种算法(想法)和nb,仅此而已。