递归思路
如果要实现节点1及节点2的指针反转
head.next.next = head;
head.next = null;
递归代码如下:
package com.aliyun.etmp.datastructure;
public class ListNode {
private int val;
private ListNode next;
private ListNode (int val, ListNode next) {
this.val = val;
this.next = next;
}
private static ListNode buildListNode() {
ListNode node5 = new ListNode(5, null);
ListNode node4 = new ListNode(4, node5);
ListNode node3 =