add: 链表的中间节点

This commit is contained in:
2020-05-10 16:57:42 +08:00
parent 304866ecbf
commit 8a69d1cfb0
9 changed files with 196 additions and 201 deletions

17
test/list/ListNode.js Normal file
View File

@ -0,0 +1,17 @@
export default class ListNode {
constructor (val) {
this.val = val
this.next = null
}
}
export const arrToList = (arr) => {
const head = new ListNode(arr[0])
let current = head
for (let n = 1, len = arr.length; n < len; n++) {
current.next = new ListNode(arr[n])
current = current.next
}
return head
}