public ListNode detectCycle(ListNode head) {
		if (head == null || head.next == null) {
			return null;
		}
		ListNode ptr0 = head;
		ListNode ptr1 = head;
		do {
			ptr0 = ptr0.next;
			if (ptr1 == null) {
				break;
			}
			ptr1 = ptr1.next;
			if (ptr1 == null) {
				break;
			}
			ptr1 = ptr1.next;
		} while (ptr1 != ptr0);

		if (ptr0 == null || ptr1 == null || ptr1.next == null) {
			return null;
		} else {
			ptr0 = head;
			while (ptr0 != ptr1) {
				ptr0 = ptr0.next;
				ptr1 = ptr1.next;
			}
			return ptr0;
		}
	}