首页 > 其他 > 详细

剑指offer---03---从尾到头打印链表---链表

时间:2018-07-27 12:37:37      阅读:88      评论:0      收藏:0      [点我收藏+]
题意
 
分析
 
代码
import java.util.*;
public class Solution{
    public ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
        ArrayList<Integer> array = new ArrayList<Integer>();
        if(listNode == null)return array;
        Stack<Integer> stack = new Stack<Integer>();
        while(listNode!=null){
            stack.push(listNode.val);
            listNode = listNode.next;
        }
        while(!stack.isEmpty()){
            array.add(stack.pop());
        }
        return array;
    }
}

剑指offer---03---从尾到头打印链表---链表

原文:https://www.cnblogs.com/buptyuhanwen/p/9376920.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!