知识点:
容器工具类:Collections
反转List方法:Collections.reverse(List)``
/**
* public class ListNode {
* int val;
* ListNode next = null;
*
* ListNode(int val) {
* this.val = val;
* }
* }
*
*/
import java.util.ArrayList;
import java.util.Collections;
public class Solution {
public ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
ArrayList<Integer>ans=new ArrayList<>();
while (listNode!=null){
ans.add(listNode.val);
listNode=listNode.next;
}
Collections.reverse(ans);
return ans;
}
}