public static ListNode detectCycle(ListNode head) {  
        // write your code here
        ListNode one=head;
        ListNode two=head;
        while (two!=null) {
            one=one.next;
            two=two.next==null?null:two.next.next;
            if (one==two)
                break;
        }
        if (two==null)
            return null;
        two=head;
        while (one!=two) {
            one=one.next;
            two=two.next;
        }
        return one;
    }