141. Linked List Cycle

 Description:

Given a linked list, determine if it has a cycle in it.

给定一个链表,确定出是否含有环

Solutions:

思路一:快指针和慢指针方法


class Solution(object): def hasCycle(self, head): """ :type head: ListNode :rtype: bool """ if head is None: return False fast=head slow=head while fast.next is not None and fast.next.next is not None: slow=slow.next fast=fast.next.next if slow==fast: return True return False

  

posted @ 2018-06-10 13:25  谦曰盛  阅读(104)  评论(0编辑  收藏  举报