【剑指Offer】输入一个链表,按链表值从尾到头的顺序返回一个ArrayList (JAVA递归实现)
作者:互联网
/**
* public class ListNode {
* int val;
* ListNode next = null;
*
* ListNode(int val) {
* this.val = val;
* }
* }
*
*/
import java.util.ArrayList;
public class Solution {
ArrayList<Integer> newArrayList=new ArrayList<Integer>();
public ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
if(listNode!=null){
this.printListFromTailToHead(listNode.next);
newArrayList.add(listNode.val);
}
return newArrayList;
}
}
标签:ListNode,val,Offer,newArrayList,ArrayList,链表,listNode,JAVA,public 来源: https://blog.csdn.net/weixin_41747528/article/details/90271426