> For the complete documentation index, see [llms.txt](https://mayanktyagi3111.gitbook.io/interview-prep/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mayanktyagi3111.gitbook.io/interview-prep/linked-list/reverse-linked-list.md).

# Reverse Linked List

Reverse a linked list. Do it in-place and in one-pass.

For example:\
Given `1->2->3->4->5->NULL`,

return `5->4->3->2->1->NULL`.<br>

```java
public class Solution {
    public ListNode reverseList(ListNode A) {
        ListNode prev = null, current = A;
        while (current.next != null) {
            ListNode temp = current.next;
            current.next = prev;
            prev = current;
            current = temp;
        }
        current.next = prev;
        return current;
    }
}
```
