Open jawakarsri opened 1 month ago
Key Steps:
1. Node Creation:
• It iterates over the original list and creates new nodes (deep copy of each node).
• It checks the HashMap to determine whether a new node needs to be created or reused from the map.
2. Mapping Random Pointers:
• For each node, the random pointer is set using the stored mapping. If the random node isn’t already in the map, it creates a copy and adds it to the map.
3. Final List:
• After the loop finishes, the deep copy list is fully constructed and returned.
Time Complexity:
Space Complexity: