> For the complete documentation index, see [llms.txt](https://algorithm.prettylog.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://algorithm.prettylog.com/top-75-leetcode-questions-to-save-your-time/problems/linked-list/206.-reverse-linked-list.md).

# 206. Reverse Linked List

\\

{% embed url="<https://leetcode.com/problems/reverse-linked-list/>" %}

> time: O(n)

> space: O(1)

```javascript
/**
 * 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 p = null;
    let c = head;

    while (c !== null) {
        const n = c.next;
        c.next = p;
        p = c;
        c = n;
    }

    return p;
};
```
