Leetcode—链表
作者:互联网
从尾到头打印链表
链接:https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/
class Solution {
public int[] reversePrint(ListNode head) {
LinkedList<Integer> sites = new LinkedList<Integer>();
while(head!=null){
sites.add(head.val);
head = head.next;
}
int n = sites.size();
int[] res = new int[n];
for(int i = 0;i<n;i++){
res[i] = sites.removeLast();
}
return res;
}
}
标签:head,LinkedList,int,sites,链表,new,Leetcode 来源: https://www.cnblogs.com/LiuYUE-fusheng/p/15636552.html