面试题 06 从尾到头打印链表 Posted on 2020-04-08 | In leetcode Words count in article: 136 | Reading time ≈ 1 题目输入一个链表的头节点,从尾到头反过来返回每个节点的值(用数组返回)。 示例 1:12输入:head = [1,3,2]输出:[2,3,1] 解法解法一:递归 JAVA12345678910111213141516171819202122232425public int[] reversePrint(ListNode head) { if (null == head) { return new int[]{}; } ListNode p = head; List<Integer> list = new ArrayList<>(); reverse(list, p); int[] result = new int[list.size()]; for (int i = 0;i < list.size();i++) { result[i] = list.get(i); } return result; } private void reverse(List<Integer> list, ListNode head) { if (null == head) { return; } reverse(list, head.next); list.add(head.val); }