SHARE
TWEET

Untitled

a guest Apr 26th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 输入一个链表,按链表值从尾到头的顺序返回一个ArrayList。
  2.  
  3. * solution1: recursion
  4. ```python3
  5. # -*- coding:utf-8 -*-
  6. # class ListNode:
  7. #     def __init__(self, x):
  8. #         self.val = x
  9. #         self.next = None
  10.  
  11. class Solution:
  12.     # 返回从尾部到头部的列表值序列,例如[1,2,3]
  13.     def __init__(self):
  14.         self.res = []
  15.     def printListFromTailToHead(self, listNode):
  16.     # write code here
  17.         if not listNode;
  18.             return self.res
  19.         self.printListFromTailToHead(listNode.next)
  20.         self.res.append(listNode.val)
  21.         return self.res
  22. ```
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top