生成链表
function ListNode(val, next) {
this.val = (val === undefined ? 0 : val)
this.next = (next === undefined ? null : next)
}
let getList = function makeList(array) {
let head = new ListNode()
let cur = head
for(let i = 0; i < array.length; i++){
let node = new ListNode(array[i])
cur.next = node
cur = cur.next
}
return head.next
}
let arr = [1, 2, 3, 4, 5]
let list1 = List(arr)
console.log(list1);