Example: Reverse Linked List ‐ Iterative - rFronteddu/general_wiki GitHub Wiki
Given the head of a singly linked list, reverse the list, and return the reversed list.
class Solution {
public ListNode reverseList (ListNode head) {
var n = head;
ListNode returnHead = null;
while (n != null) {
var next = n.next;
n.next = returnHead;
returnHead = n;
n = next;
}
return returnHead;
}
}