剑指offer01 JZ6 从尾到头打印链表
从尾到头打印链表
https://www.nowcoder.com/practice/d0267f7f55b3412ba93bd35cfa8e8035?tpId=13&tqId=23278&ru=/exam/oj/ta&qru=/ta/coding-interviews/question-ranking&sourceUrl=%2Fexam%2Foj%2Fta%3Fpage%3D1%26tpId%3D13%26type%3D13
- 递归到最后节点
2.使用list添加节点
3.结果就是返现添加
/**
* public class ListNode {
* int val;
* ListNode next = null;
*
* ListNode(int val) {
* this.val = val;
* }
* }
*
*/
import java.util.ArrayList;
public class Solution {
public ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
ArrayList<Integer> result=new ArrayList();
resovle(listNode,result);
return result;
}
public void resovle(ListNode head ,ArrayList<Integer> result)
{
if(head!=null)
{
resovle(head.next,result);
result.add(head.val);
}
}
}