LeetCode:32.随机链表的复制
目录
1.随机链表的复制
1.随机链表的复制
class Solution {unordered_map<Node*, Node*> hash;
public:Node* copyRandomList(Node* head) {if(head == nullptr)return nullptr;if(!hash.count(head)){Node* newhead = new Node(head->val);hash[head] = newhead;newhead->next = copyRandomList(head->next);newhead->random = copyRandomList(head->random);}return hash[head];}
};