你需要将一个单链表,按照从表头向表尾的顺序转化为一个序列。
示例1
输入
{1,1,4,5,1,4}
输出
[1,1,4,5,1,4]
加载中...
import java.util.*; /* * public class ListNode { * int val; * ListNode next = null; * public ListNode(int val) { * this.val = val; * } * } */ public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param head ListNode类 * @return int整型ArrayList */ public ArrayList
listnodeToVector (ListNode head) { // write code here } }
/** * struct ListNode { * int val; * struct ListNode *next; * ListNode(int x) : val(x), next(nullptr) {} * }; */ class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param head ListNode类 * @return int整型vector */ vector
listnodeToVector(ListNode* head) { // write code here } };
#coding:utf-8 # class ListNode: # def __init__(self, x): # self.val = x # self.next = None # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param head ListNode类 # @return int整型一维数组 # class Solution: def listnodeToVector(self , head ): # write code here
# class ListNode: # def __init__(self, x): # self.val = x # self.next = None # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param head ListNode类 # @return int整型一维数组 # class Solution: def listnodeToVector(self , head: ListNode) -> List[int]: # write code here
{1,1,4,5,1,4}
[1,1,4,5,1,4]