チェーンの逆順(JavaScript版)
1574 ワード
1 function reverseLinkedList(head) {
2
3 if (head === null || head.next === null) {
4 return head;
5 }
6 let newHead = null
7 while (head) {
8 let next = head.next
9 head.next = newHead
10 newHead = head
11 head = next
12 }
13 return newHead
14 }