public class ListNode {
int val;
ListNode next;
// 构造函数
public ListNode() {
}
public ListNode(int val) {
this.val = val;
}
public ListNode(int val, ListNode next) {
this.val = val;
this.next = next;
}
}
public static class DoubleListNode {
int val;
DoubleListNode prev;
DoubleListNode next;
public DoubleListNode() {
}
public DoubleListNode(int val) {
this.val = val;
}
public DoubleListNode(int val, DoubleListNode prev, DoubleListNode next) {
this.val = val;
this.prev = prev;
this.next = next;
}
}
while (p != null) {
temp = p.next;
p.next = pre;
pre = p;
p = temp;
}
// 创建栈
Stack<ListNode> stackNode = new Stack<ListNode>();
视频讲解
可以把环分成x, y, z,分析三者之间的数学关系