I think my answer is correct but it judge me wrong...

  • 3
    	    public ListNode detectCycle(ListNode head) {
            ListNode h = new ListNode(-1);
            h.next = head;
            ListNode result = this.detect(h);
            return result;
        private ListNode detect(ListNode head) {
            // Set<Integer> numSet = new HashSet<Integer>();
            ListNode p = head;
            	ListNode tmp = p.next.next;
            	p.next.next = p;
            	p.next = tmp;
            	if(p.next.next == p)
            		return p.next;
            return null; 

    It works fine on my computer, yet gives wrong answer. Can someone help?

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.