https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/
Java (借助栈
class Solution {
public int[] reversePrint(ListNode head) {
linkedList stack = new linkedList(); //辅助栈
//元素入栈O(n)
while(head != null){
stack.addLast(head.val);
head = head.next;
}
//根据栈大小创建数组
int[] res = new int[stack.size()];
//栈内元素弹出到数组中O(n)
for(int i=0;i
Java (递推
class Solution {
//递推
ArrayList tmp = new ArrayList();
public int[] reversePrint(ListNode head) {
recur(head);
int[] res = new int[tmp.size()];
for(int i = 0; i < res.length; i++)
res[i] = tmp.get(i);
return res;
}
void recur(ListNode head) {
if(head == null) return; //头节点为空判断
recur(head.next);
tmp.add(head.val);
}
}



