Skip to content

Commit 16ea231

Browse files
committed
Copy List With Random Pointer: hahsmap, recursion.
1 parent d08a5e9 commit 16ea231

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "../Header.h"
2+
3+
using namespace std;
4+
5+
RandomListNode *copyRandomList(RandomListNode *head) {
6+
if (!head) return nullptr;
7+
// new node finded
8+
if (hash.find(head) == hash.end()) {
9+
hash[head] = new RandomListNode(head->label);
10+
hash[head]->random = copyRandomList(head->random);
11+
hash[head]->next = copyRandomList(head->next);
12+
}
13+
return hash[head];
14+
}

0 commit comments

Comments
 (0)