题目描述
尾递归java
样例
blablabla
C++ 代码
class Solution {
int i = 0;
int[] ans;
public int[] printListReversingly(ListNode head) {
if(head == null) return new int[0];
ans = new int[10000];
dfs(head);
return Arrays.copyOfRange(ans,0,i);
}
public void dfs(ListNode head){
if(head == null) return;
dfs(head.next);
ans[i++] = head.val;
}
}