/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
public class Solution {
public ListNode reverseList(ListNode head) {
if (head == null || head.next == null) {
return head;
}
ListNode second = head.next;
head.next = null;
ListNode rest = reverseList(second);
second.next = head;
return rest;
}
}
reverse list (recursive)
最新推荐文章于 2023-08-04 11:19:34 发布