[编程题] 反转单链表
作者:互联网
interface LinkedList {
val: number
next: LinkedList | null
}
function reverseLinkedlist(head: LinkedList): LinkedList {
if (head === null || head.next === null) {
return head
}
const prev = reverseLinkedlist(head.next)
head.next.next = head
head.next = null
return prev
}
标签:head,单链,return,LinkedList,反转,编程,next,prev,null 来源: https://www.cnblogs.com/toddforsure/p/reverse-linkedlist.html