aman247av / Hacktoberfest-Coding-Challenges

This repository is dedicated to solving and sharing coding problems from platforms like CodeForces, LeetCode, GeeksforGeeks, Atcoder and CodeChef, etc. Contribute new coding questions, learn from the community, and boost your problem-solving skills while participating in Hacktoberfest! Welcome to
MIT License
1 stars 22 forks source link

Swapping Entire Nodes Without Direct Value Swap #4

Closed Saireddy1369 closed 1 week ago

Saireddy1369 commented 1 week ago
  1. In most solutions, after locating the nodes at a k distance from the start and end, the values of the nodes are directly swapped, which is a basic approach.
  2. In my solution, instead of swapping values, the entire nodes are swapped by carefully adjusting the pointers while maintaining the previous and next nodes of the target nodes.

In simpler terms, instead of swapping the data values -> my solution swaps the memory location of the nodes.

The important function is swapNodes(ListNode head, int k), while the other functions are provided to support the execution of test cases.

Saireddy1369 commented 1 week ago

done changed file name