Back to course home
0% completed
Vote For New Content
C# solution without tracking previous node
gabbygabbylexy
Jun 10, 2025
public class Solution { public ListNode swapPairs(ListNode head) { // TODO: Write your code here if (head == null || head.Next == null) return head; var dummy = new ListNode(0); dummy.Next = head; var current = dummy; while (current.Next != null && current.Next.Next != null) { var first = current.Next; var second = current.Next.Next; current.Next = second; first.Next = second.Next; second.Next = first; current = first; } return dummy.Next; } }
0
0
Comments
Comments
On this page