美文网首页
leetcode 141. 环形链表

leetcode 141. 环形链表

作者: 七齐起器 | 来源:发表于2021-02-24 17:56 被阅读0次

    class Solution(object):

        def hasCycle(self, head):

            tag = False 

            #边界条件

            if head == None :

                return None

            #边界条件 单节点无环

            if head != None and head.next == None :

                return False

             #边界条件 单节点有环

            if head != None and head.next == head:

                return True 

            fast = head.next;

            low  = head;

            while (fast != low ):

                try:

                    fast = fast.next.next;

                    low  = low.next;

                    if fast == low:

                        tag = True 

                        break 

                except:

                    break

            return tag 

    相关文章

      网友评论

          本文标题:leetcode 141. 环形链表

          本文链接:https://www.haomeiwen.com/subject/swnsfltx.html