Package crack

Source Code of crack.Solution2_5

package crack;

import leetcode.ListNode;

public class Solution2_5 {
    public ListNode find(ListNode head) {
        ListNode n1 = head;
        ListNode n2 = head;
        boolean find = false;

        while (n2 != null && n2.next != null) {
            n1 = n1.next;
            n2 = n2.next.next;
            if (n2 == n1) {
                find = true;
                break;
            }
        }

        if (!find)
            return null;

        n1 = head;

        while (n1 != n2) {
            n1 = n1.next;
            n2 = n2.next;
        }

        return n1;
    }
}
TOP

Related Classes of crack.Solution2_5

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.