| 6 | } |
| 7 | |
| 8 | public class ReverseLinkedList { |
| 9 | public ListNode reverseList(ListNode head) { |
| 10 | ListNode prev = null; // Previous node, initially null |
| 11 | ListNode curr = head; // Current node starts from the head |
| 12 | while (curr != null) { |
| 13 | ListNode next = curr.next; // Store next node |
| 14 | curr.next = prev; // Reverse the current node's pointer |
| 15 | prev = curr; // Move prev to current |
| 16 | curr = next; // Move curr to next |
| 17 | } |
| 18 | return prev; // New head of the reversed list |
| 19 | } |
| 20 | } |
nothing calls this directly
no outgoing calls
no test coverage detected