Leetcode:剑指 Offer 06. 从尾到头打印链表


while比for的效率更低

class Solution {
    public int[] reversePrint(ListNode head) {
        Stack stack=new Stack();
        if(head==null){
            return new int[0];
        }
        int count=0;
        while(head!=null){
            stack.push(head.val);
            head=head.next;
        }
        int size=stack.size();
        int[] res=new int[size];
        //while比for的效率更低
        for(int i=0;i