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