题目描述:
方法:递归法
class Solution{ ArrayList<Integer> tmp = new ArrayList<>(); 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);//回溯阶段将当前节点值加入列表 } }
标签:tmp,06,Offer,int,链表,new From: https://www.cnblogs.com/zhz123567/p/17457087.html