标签:class integer null return head solution arraylist print new
输入一个链表,按链表值从尾到头的顺序返回一个ArrayList。
import java.util.ArrayList;
public class Solution {
public ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
ListNode cur = listNode;
ArrayList<Integer> list = new ArrayList<>();
if(cur == null){
return list;
}
while(cur != null){
list.add(0, cur.val);
cur = cur.next;
}
return list;
}
}
每次插入链表头,尾插法
标签:class integer null return head solution arraylist print new
原文地址:https://www.cnblogs.com/ruanshuai/p/12170742.html