题目
https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/
思路
遍历链表到数组 然后反转后返回即可
代码
/**
*
* @date: 2020-03-10 22:00
* @param: * @param head:
* @return: * @return: int[]
* @author: wwh
* @Description: 2020年03月10日21:50:33 -2020年03月10日22:00:48
* 面试题06. 从尾到头打印链表
* https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/
* 思路:遍历链表到list 然后翻转后返回数组即可
*/
public int[] reversePrint(ListNode head) {
if(head==null){
return new int[0];
}
List<Integer> temp= new ArrayList<>();
while (head!=null){
temp.add(head.val);
head = head.next;
}
int[] arr = new int[temp.size()];
for (int i1 = temp.size()-1 ; i1 >=0 ; i1--) {
arr[temp.size()-1-i1] = temp.get(i1);
}
return arr;
}