@@ -0,0 +1,1901 @@
+//  Copyright 2016 The Sawdust Open Source Project%0A//%0A// Licensed under the Apache License, Version 2.0 (the %22License%22);%0A// you may not use this file except in compliance with the License.%0A// You may obtain a copy of the License at%0A//%0A//     http://www.apache.org/licenses/LICENSE-2.0%0A//%0A// Unless required by applicable law or agreed to in writing, software%0A// distributed under the License is distributed on an %22AS IS%22 BASIS,%0A// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A// See the License for the specific language governing permissions and%0A// limitations under the License.%0A//%0A%0A// Given a linked list, return the node where the cycle begins.%0A// If there is no cycle, return null.%0A// Note: Do not modify the linked list.%0A// Follow up:%0A// Can you solve it without using extra space?%0A%0Aclass ListNode %7B%0A    int val;%0A    ListNode next;%0A%0A    ListNode(int x) %7B%0A        val = x;%0A        next = null;%0A    %7D%0A%7D%0A%0Apublic class Leetcode142LinkedListCycleII %7B%0A%0A    // beats 20.26%25 of java submissions.%0A    public static ListNode detectCycle(ListNode head) %7B%0A        ListNode f = head;%0A        ListNode l = head;%0A        while (!(f == null %7C%7C f.next == null)) %7B%0A            f = f.next.next;%0A            l = l.next;%0A            if (f == l && f != null) %7B%0A                while (head != f) %7B%0A                    head = head.next;%0A                    f = f.next;%0A                %7D%0A                return f;%0A            %7D%0A        %7D%0A        return null;%0A    %7D%0A%0A    // beats 20.26%25 of java submissions.%0A    // it depends on there is no value of Integer.MIN_VALUE existing%0A    public static ListNode detectCycle2(ListNode head) %7B%0A        while (null != head) %7B%0A            if (Integer.MIN_VALUE != head.val) %7B%0A                head.val = Integer.MIN_VALUE;%0A            %7D else %7B%0A                return head;%0A            %7D%0A            head = head.next;%0A        %7D%0A        return null;%0A    %7D%0A%7D%0A

Add Leetcode142LinkedListCycleII