python easy to understand two pointer solution

  • 0
    # Definition for singly-linked list.
    # class ListNode(object):
    #     def __init__(self, x):
    #         self.val = x
    # = None
    class Solution(object):
        def detectCycle(self, head):
            :type head: ListNode
            :rtype: ListNode
            if head==None or
                return None
            while fast!=None and!=None and slow!=fast:
            if fast==None or
                return None
            while slow!=fast:
            return slow

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.