206. Reverse Linked List
作者:
jluemmmm | 来源:发表于
2020-08-30 19:48 被阅读0次
- Runtime: 84 ms, faster than 52.12%
- Memory Usage: 38.7 MB, less than 30.77%
/**
* Definition for singly-linked list.
* function ListNode(val, next) {
* this.val = (val===undefined ? 0 : val)
* this.next = (next===undefined ? null : next)
* }
*/
/**
* @param {ListNode} head
* @return {ListNode}
*/
var reverseList = function(head) {
let prev = null
let cur = head
while(cur) {
let temp = cur.next
cur.next = prev
prev = cur
cur = temp
}
return prev
};
本文标题:206. Reverse Linked List
本文链接:https://www.haomeiwen.com/subject/gewesktx.html
网友评论