题解 | 序列链表化
序列链表化
https://www.nowcoder.com/practice/a407f7e495084084b1e1f628dfd769fd
/**
* struct ListNode {
* int val;
* struct ListNode *next;
* ListNode(int x) : val(x), next(nullptr) {}
* };
*/
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param arr int整型vector
* @return ListNode类
*/
ListNode* vectorToListnode(vector<int>& arr) {
// write code here
if(arr.size()==0)return nullptr;
auto head=new ListNode(arr[0]);
auto cur=head;
for(int i=1;i<arr.size();i++){
cur->next=new ListNode(arr[i]);
cur=cur->next;
}
return head;
}
};

