博客域名:
http://www.xnerv.wang
原题页面: https://oj.leetcode.com/problems/linked-list-cycle/
题目类型:
难度评价:★
本文地址: http://blog.csdn.net/nerv3x3/article/details/3465710
原题页面: https://oj.leetcode.com/problems/linked-list-cycle/
题目类型:
难度评价:★
本文地址: http://blog.csdn.net/nerv3x3/article/details/3465710
Given a linked list, determine if it has a cycle in it.
Follow up:
Can you solve it without using extra space?
确定链表是否有环。记得好像是编程之美上的题目?
class Solution:
# @param head, a ListNode
# @return a boolean
def hasCycle(self, head):
if None == head:
return False
fast = slow = head
while True:
fast = fast.next
if None == fast:
return False
fast = fast.next
if None == fast:
return False
slow = slow.next
if fast == slow:
return True