We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d08a5e9 commit 16ea231Copy full SHA for 16ea231
Hard/138_Copy-List-with-Random-Pointer.cpp
@@ -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