1/*
2public class ListNode {
3 public int val;
4 public ListNode next;
5 public ListNode(int x) { val = x; next = null; }
6}
7*/
8
9public static ListNode[] reverse_linked_list(ListNode head) {
10
11 ListNode prev = null;
12 ListNode current = head;
13 ListNode next;
14
15 ListNode tail = head;
16
17 while (current != null) {
18
19 next = current.next;
20 current.next = prev;
21 prev = current;
22 current = next;
23 }
24
25 head = prev;
26
27 ListNode[] result = {head, tail};
28
29 return result;
30}