赞
踩
- /*
- // Definition for a Node.
- class Node {
- public:
- int val;
- Node* next;
- Node* random;
-
- Node(int _val) {
- val = _val;
- next = NULL;
- random = NULL;
- }
- };
- */
-
- class Solution {
- public:
- Node* copyRandomList(Node* head) {
- unordered_map<Node*, Node*> OriMap;
- Node* cur = head;
- while (cur) {
- OriMap[cur] = new Node(cur->val);
- cur = cur->next;
- }
-
- cur = head;
- while (cur) {
- OriMap[cur]->next = OriMap[cur->next];
- OriMap[cur]->random = OriMap[cur->random];
- cur = cur->next;
- }
- return OriMap[head];
- }
- };
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。