public ListNode detectCycle(ListNode head) {
		ListNode slow = head, quick = head;
		while (slow != null && quick != null) {
			slow = slow.next;
			quick = quick.next;
			if (quick.next != null)
				quick = quick.next;
			if (slow == quick)
				break;
		}
		if (quick == null)
			return null;
		// http://fisherlei.blogspot.com/2013/11/leetcode-linked-list-cycle-ii-solution.html
		// X+K = aY, slow and quick meet in K, so, they have to move X times to
		// loacte
		// the position of the cycle.
		slow = head;
		while (slow != quick) {
			quick = quick.next;
			slow = slow.next;
		}

		return slow;
	}