一 单链表反转
1 迭代
function reverseLink (link) {
if (!link.head || !link.head.next) {
return link
} else {
let current = link.head
let pre = null
while(current) {
const next = current.next
current.next = pre
pre = current
current = next
}
link.head = pre
}
}
2 递归
function reverseLink (link) {
const head = link.head
if (!head || !head.next) {
link.head = head
return link
} else {
link.head = head.next
reverseLink(link)
head.next.next = head
head.next = null
}
}
链表中环的检测
两个有序的链表合并
删除链表倒数第 n 个结点
求链表的中间结点
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。