题解 | #反转链表#
反转链表
https://www.nowcoder.com/practice/75e878df47f24fdc9dc3e400ec6058ca
import java.util.*;
/*
public class ListNode {
int val;
ListNode next = null;
ListNode(int val) {
this.val = val;
}
}*/
public class Solution {
public ListNode ReverseList(ListNode eNode) {
if(eNode == null || eNode.next == null)
return eNode;
ArrayList<ListNode> arrayList= new ArrayList<>();
ListNode pre = null;
while(eNode != null){
ListNode listNote = new ListNode(eNode.val);
arrayList.add(listNote);
eNode = eNode.next;
}
pre = arrayList.get(arrayList.size() - 1);
for(int i = arrayList.size() - 1; i > 0; i--){
arrayList.get(i).next = arrayList.get(i - 1);
}
return pre;
}
}