/*
public class ListNode {
int val;
ListNode next = null;
ListNode(int val) {
this.val = val;
}
}*/
public class Solution {
public ListNode ReverseList(ListNode head) {
if(head == null || head.next == null) return head;
ListNode p = ReverseList(head.next);
head.next.next = head;
head.next = null;
return p;
}
}
16、反转链表(递归方法)
最新推荐文章于 2024-02-06 20:41:38 发布