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

View File

@ -1,20 +1,5 @@
import { hasCycle } from '../../src/list/linked-list-cycle'
function ListNode (val) {
this.val = val
this.next = null
}
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
}
import { arrToList } from './ListNode'
test('环形链表', () => {
const list = arrToList([1, 2, 3])