billryan / algorithm-exercise

Data Structure and Algorithm notes. 数据结构与算法/leetcode/lintcode题解/

Home Page:https://algorithm.yuanbin.me

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

我错了

daidai21 opened this issue · comments

commented

咱两的思路不一样
class NewNode:
def init(self, val):
self.value = val
self.next = next

def judge_circle(self, head):
    slow = head
    fast = head
    while slow and fast:
        fast = fast.next.next
        slow = slow.next
        if fast == slow:
            break
    if fast and slow and (fast == slow):
        return True
    else:
        return False

我的就直接 fast = fast.next.next了

你这种对于无环的有考虑过吗?fast 走到最后一个节点的时候,fast.next 为 null, 那么 fast.next.next 会报错的

commented

对的,我没有考虑链表无环且还是奇数的长度,还是自己考虑的不够全面,谢谢