Skip to content

Instantly share code, notes, and snippets.

@jason51285128
Created January 21, 2020 07:35
Show Gist options
  • Save jason51285128/73103098496731bbb031b5f4b80d0d8c to your computer and use it in GitHub Desktop.
Save jason51285128/73103098496731bbb031b5f4b80d0d8c to your computer and use it in GitHub Desktop.
单向链表翻转
/*
head:
{
val: xx,
next: xx
}
tail:
{
val:xx,
next: null
}
*/
function revertList(head)
{
// write code here
var last = null
var node = head
while (node) {
let tmp = node.next
head.next = last
last = node
node = tmp
}
return last
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment