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;
    }
}
上一篇:pdf点击超链接后返回:alt+ 向左 /向右


下一篇:PHP-Codeigniter 3.0.4与我的服务器上的404页面未找到错误