My Accepted Solution


  • 0
    K
    public boolean hasCycle(ListNode head) 
    {
        ListNode faster = head;
        ListNode slower = head;
        
        while (faster != null)
        {
            faster = faster.next;
            
            if (faster == null)
            {
                return false;
            }
            else
            {
                faster = faster.next;
            }
            
            slower = slower.next;
            
            if (faster == slower)
            {
                return true;
            }
        }
        return false;
    }

Log in to reply
 

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