My java solution


  • 0
    C
      public class Solution{
      public boolean hasCycle(ListNode head) {
    	
    	if(head == null)return false;
    	
    	if(head.next == null)return false;
    	
    	ListNode slow = head;
    	ListNode fast = head.next;
    	
    	while((fast != null) &&(fast.next!= null)&& (fast.next.next != null))
    	{
    		if(slow == fast)return true;
    		
    		slow = slow.next;
    		
    		fast = fast.next.next;
    	}
    	return false;
    }
    

    }


Log in to reply
 

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