Linked List Problems: Swapping, Removal, Intersection, and Cycle Detection
Swapping Nodes in Pairs
Problem: Given a linked list, swap every two adjacent nodes and return its head.
Iterative Approach:
class ListNode {
int val;
ListNode next;
ListNode(int val) { this.val = val; }
}
class Solution {
public ListNode swapPairs(ListNode head) {
if (head == null || head.next == null) {
...
Posted on Sat, 09 May 2026 04:52:05 +0000 by psurrena