剑指 Offer 06. 从尾到头打印链表
class Solution { ArrayList<Integer> tmp = new ArrayList<Integer>(); 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); } }
大佬解析:
https://leetcode.cn/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/solution/mian-shi-ti-06-cong-wei-dao-tou-da-yin-lian-biao-d/