Back to course home
0% completed
Vote For New Content
in-place linked list reversal is more of an intellectual exercise than practical real-world code
Thomas MinhTu Hoang
Jul 13, 2025
// public class ListNode { // public int Val = 0; // public ListNode Next; // public ListNode(int value) { // this.Val = value; // } // } public class Solution { public ListNode reverse(ListNode head) { if (head?.Next == null) return head; ListNode fwd = head; ListNode bwd = null; while (fwd != null) { bwd = new ListNode(fwd.Val) { Next = bwd }; fwd = fwd.Next; } return bwd; }
0
0
Comments
Comments
Thomas MinhTu Hoang3 months ago
In practical real-world programming, mutating a shared data structure is usually a bad idea.
On this page
Problem Statement
Try it yourself