Java Algorithms: Copying List with Random Pointer (LeetCode)by@rakhmedovrs
147,125 reads
147,125 reads

Java Algorithms: Copying List with Random Pointer (LeetCode)

by Ruslan Rakhmedov4mAugust 31st, 2022
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow
EN

Too Long; Didn't Read

Let’s start from solving the first subproblem. Let’s do simple thing iterate through linked list and create a copy for every node in it. I choose HashMap for storing pairs like old node -> new node. As long as we’re going to iterate from head of the list to tail let’s also introduce temp variable and set it to be the head of the list.
featured image - Java Algorithms: Copying List with Random Pointer (LeetCode)
Ruslan Rakhmedov HackerNoon profile picture
Ruslan Rakhmedov

Ruslan Rakhmedov

@rakhmedovrs

Senior Software Engineer. As a hobby I do competitive programming

Learn More
LEARN MORE ABOUT @RAKHMEDOVRS'S
EXPERTISE AND PLACE ON THE INTERNET.

Share Your Thoughts

About Author

Ruslan Rakhmedov HackerNoon profile picture
Ruslan Rakhmedov@rakhmedovrs
Senior Software Engineer. As a hobby I do competitive programming

TOPICS

Languages

THIS ARTICLE WAS FEATURED IN...

Permanent on Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite
L O A D I N G
. . . comments & more!