1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
import java.util.Stack; import java.util.ArrayList;
public class Solution { public ArrayList<Integer> printListFromTailToHead(ListNode listNode) { ArrayList<Integer> list = new ArrayList<Integer>(); ListNode head = listNode; Stack stack = new Stack(); while (head != null){ stack.push(head.val); head = head.next; } while (!stack.empty()){ list.add((Integer) stack.pop()); } return list; } }
|
近期评论