206. Reverse Linked List#
1public ListNode reverseList(ListNode head) {
2 ListNode newHead = null;
3
4 while (head != null) {
5 ListNode next = head.next;
6 head.next = newHead;
7 newHead = head;
8 head = next;
9 }
10
11 return newHead;
12}