码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode-面试题6-从尾到头打印链表

时间:2020-04-02 17:39:14      阅读:49      评论:0      收藏:0      [点我收藏+]

标签:public   com   面试   efi   leetcode   array   color   turn   eve   

 题目描述:

技术图片

 

 java

/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) { val = x; }
 * }
 */
class Solution {
    public int[] reversePrint(ListNode head) {
        Stack<Integer> stack = new Stack<>();
        while(head != null){
            stack.push(head.val);
            head = head.next;
        }
        int size = stack.size();
        int [] array = new int[size];
        for(int i = 0; i < size; i++){
            array[i] = stack.pop();
        }
        return array;

    }
}

 

leetcode-面试题6-从尾到头打印链表

标签:public   com   面试   efi   leetcode   array   color   turn   eve   

原文地址:https://www.cnblogs.com/oldby/p/12621003.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!