public ListNode detectCycle(ListNode head) {
		if(head == null || head.next == null)
			return null;
		ListNode fast = head;
        ListNode slow = head;
		while(fast != null && fast.next != null){
			slow = slow.next;
        	fast = fast.next.next;
        	if(slow.equals(fast))
        		break;
		}
		if(!slow.equals(fast))
			return null;
		//find the begin node;
		ListNode p,temp,prev;
		p  = head;
		prev = slow;
		//find the prev node of q;
		while(true){
			temp = findPrevNodeInCycle(prev);
			p = findPrevNodeInLink(head,prev);
			if(temp.equals(p) ){
				prev = p;
				if(prev.equals(head))
					return head;
			}
			
			else
				return prev;
		}
    }