Concise Java Solution


  • 2
    M
     public boolean hasCycle(ListNode head) {
        ListNode fast = head;
    
    	while (fast != null && fast.next != null) {
    		head = head.next;
    		fast = fast.next.next;
    		if (head == fast)
    			return true;
    	}
    
    	return false;
    }

Log in to reply
 

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