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

题意
 
分析
 
代码
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;
    }
}

猜你喜欢

转载自www.cnblogs.com/buptyuhanwen/p/9376920.html
今日推荐