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

# 206. Reverse Linked List

![](/files/-MdzwQSHNBCT_G8gzQUs)

```
Input: 1->2->3->4->5->NULL
Output: 5->4->3->2->1->NULL
```

iterative version

1. try to think about making  1 -> NULL
2. &#x20;`1->2->3->4->5->NULL`   becomes    `NULL<-1  2->3->4->5->NULL`

```java
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) { val = x; }
 * }
 */
class Solution {
    public ListNode reverseList(ListNode head) {
        ListNode nHead = null;
        ListNode curr = head;
        
        while (curr != null) {
            ListNode nextTemp = curr.next; // store temp next
            curr.next = nHead; //link to reverse
            nHead = curr; // move (most left node first
            curr = nextTemp; //move
        }
        return nHead;
    }
}
```
