The third question list to prove safety offer Java

Enter a list, the value returned by a ArrayList list sequentially from the tail to the head.

import java.util.ArrayList;
public class Solution {
    public ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
        ArrayList<Integer> arrayList =new ArrayList<Integer>();
        int [] tem = new int[1024];
        int step =0;
        ArrayList<Integer> result =new ArrayList<Integer>();
        if(listNode == null){
            return arrayList;
        }else {
            while (listNode != null) {
                tem[step] =listNode.val;
                step++;
                //arrayList.add(listNode.val);
                listNode = listNode.next;

            }
        }
        for(int i=step-1;i>=0;i--){
            arrayList.add(tem[i]);
        }
        return arrayList;
        
    }
}

 

Guess you like

Origin blog.csdn.net/blood_ing_/article/details/93717345