Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reverse Linked List #24

Open
cheatsheet1999 opened this issue Sep 8, 2021 · 0 comments
Open

Reverse Linked List #24

cheatsheet1999 opened this issue Sep 8, 2021 · 0 comments

Comments

@cheatsheet1999
Copy link
Owner

Given the head of a singly linked list, reverse the list, and return the reversed list.

Screen Shot 2021-09-08 at 9 07 14 AM

reverseLinkedlist

With the help with ES6, I found this problem can be easy to solve

var reverseList = function(head) {
    let [prev, current] = [null, head];
    while(current) {
        [prev, current.next, current] = [current, prev, current.next]
    }
    return prev;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant