Created
January 21, 2020 07:35
-
-
Save jason51285128/73103098496731bbb031b5f4b80d0d8c to your computer and use it in GitHub Desktop.
单向链表翻转
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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