题解 | 序列链表化
序列链表化
https://www.nowcoder.com/practice/a407f7e495084084b1e1f628dfd769fd
import java.util.*;
/*
* public class ListNode {
* int val;
* ListNode next = null;
* public ListNode(int val) {
* this.val = val;
* }
* }
*/
public class Solution {
public ListNode vectorToListnode (int[] arr) {
if(arr.length==0)return null;
ListNode head = new ListNode(0);
ListNode res = head;
for (int i = 0; i < arr.length; i++) {
head.val = arr[i];
ListNode temp = new ListNode(0);
if (i != arr.length - 1) {
head.next = temp;
head = head.next;
}
}
return res;
}
}
文远知行公司福利 588人发布
