剑指 Offer 06. 从尾到头打印链表 Posted on 2022-07-02 | In leetcode Words count in article: 126 | Reading time ≈ 1 题目请实现一个函数,把字符串 s 中的每个空格替换成”%20”。 示例 1:12输入:head = [1,3,2]输出:[2,3,1] 提示: 0 <= 链表长度 <= 10000 解法解法一:JAVA123456789101112131415161718public int[] reversePrint(ListNode head) { List<Integer> result = new ArrayList<>(); travel(head, result); int[] array = new int[result.size()]; for (int i = 0;i < array.length;i++) { array[i] = result.get(i); } return array; } private void travel(ListNode head, List<Integer> result) { if (Objects.isNull(head)) { return; } travel(head.next, result); result.add(head.val); }