Skip to content

Commit

Permalink
chore: azl397985856#206 优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
luzhipeng committed May 22, 2019
1 parent 24f429c commit 71c42fa
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions problems/206.reverse-linked-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,18 @@ A linked list can be reversed either iteratively or recursively. Could you imple
* @return {ListNode}
*/
var reverseList = function(head) {
const dummyHead = {
next: head
}
let current = dummyHead.next;
if (!head || !head.next) return head;

let cur = head;
let pre = null;

while(current) {
const next = current.next;
current.next = pre;
pre = current;
current = next;
while(cur) {
const next = cur.next;
cur.next = pre;
pre = cur;
cur = next;
}

return pre;
};

Expand Down

0 comments on commit 71c42fa

Please sign in to comment.