Fast&Slow(快慢指针)
Fast & Slow(快慢指针)
快慢指针的应用
// 基础代码
public static class SingleLinkedList {
private Node head = null;
class Node {
private Node next;
private Double data;
public Node(Double data) {
this.data = data;
}
}
public void addNode(Double data) {
if (head == null) {
head = new Node(data);
return;
}
Node temp = head;
while (temp.next != null) {
temp = temp.next;
}
temp.next = new Node(data);
}
public void makeLoop() {
if (head == null) {
return;
}
Node temp = head;
while (temp.next != null) {
temp = temp.next;
}
temp.next = head;
}
}



Last updated