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

【算法-简单】反转链表 #88

Open
AwesomeDevin opened this issue May 23, 2023 · 0 comments
Open

【算法-简单】反转链表 #88

AwesomeDevin opened this issue May 23, 2023 · 0 comments

Comments

@AwesomeDevin
Copy link
Owner

题解: https://leetcode.cn/problems/UHnkqh/solution/jian-dan-yi-dong-javac-pythonjs-dong-hua-gy6w/

/**
 * 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 current = head
    let prev = null
    while(current !== null) {
        const next = current.next
        current.next = prev
        prev = current
        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