思路
- 遍历列表然后把数值放到数组中返回
public int[] reversePrint(ListNode head) {
// 注意边界值,数组初始化赋值为0
if (head == null) return new int[0];
int top = -1;
int[] list = new int[10000];
while(head != null) {
top++;
list[top] = head.val;
head = head.next;
}
int[] out = new int[top + 1];
int index = 0;
while(top>=0) {
out[index] = list[top];
top--;
index++;
}
return out;
}
Q.E.D.