public class FindCircleBeginning {
class ListNode {
public int id;
public ListNode next;
public ListNode() {
}
public ListNode(int id, ListNode next) {
this.id = id;
this.next = next;
}
}
public ListNode createList(int n) {
ListNode head = new ListNode(0,null);
ListNode p = head;
for (int i = 1; i <= n; ++i) {
ListNode tmp = new ListNode(i,null);
p.next = tmp;
p = tmp;
}
return head;
}
/**
* @param n 链表总长度
* @param m 环所在的位置,head为0,不计算入内,所以长度为n的链表位置分别为1-n
* @return
*/
public ListNode createList(int n, int m) {
if (m >= n || m <= 0) {
System.out.println("Cannot creat a linkedlist with a circle!");
return null;
}
ListNode head = new ListNode(0,null);
ListNode p = head;
for (int i = 1; i <= n; ++i) {
ListNode tmp = new ListNode(i,null);
public class FindCircleBeginning { class ListNode { public int id; public ListNode next; public ListNode() { } public ListNode(int id, ListNode next) { this.id = id; this.