leetcode 138. Copy List with Random Pointer
来源:互联网 发布:本拉登 中国 知乎 编辑:程序博客网 时间:2024/06/14 03:56
138. Copy List with Random Pointer
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.
Return a deep copy of the list.
/** * Definition for singly-linked list with a random pointer. * struct RandomListNode { * int label; * RandomListNode *next, *random; * RandomListNode(int x) : label(x), next(NULL), random(NULL) {} * }; */class Solution {public: RandomListNode *copyRandomList(RandomListNode *head) { if (!head) return NULL; map<RandomListNode *,RandomListNode *> copy; //copy point RandomListNode *p = head; while(p) { copy[p] = new RandomListNode(p->label); p = p->next; } // copy next and random p = head; while(p) { copy[p]->next = copy[p->next]; copy[p]->random = copy[p->random]; p = p->next; } return copy[head]; }};
阅读全文
0 0
- LeetCode 138. Copy List with Random Pointer
- [Leetcode] 138. Copy List with Random Pointer
- LeetCode 138. Copy List with Random Pointer
- [leetcode] 138. Copy List with Random Pointer
- LeetCode 138. Copy List with Random Pointer
- LeetCode 138. Copy List with Random Pointer
- leetcode.138. Copy List with Random Pointer
- LeetCode-138.Copy List with Random Pointer
- Leetcode 138. Copy List with Random Pointer
- [Leetcode]138. Copy List with Random Pointer
- LeetCode 138. Copy List with Random Pointer
- [LeetCode] 138. Copy List with Random Pointer
- [LeetCode]138. Copy List with Random Pointer
- LeetCode 138. Copy List with Random Pointer
- Leetcode-138. Copy List with Random Pointer
- Leetcode 138. Copy List with Random Pointer
- leetcode 138. Copy List with Random Pointer
- Leetcode 138. Copy List with Random Pointer
- 罗氏线圈
- k8s使用技巧
- Kmeans基本思想以及和SVM的区别
- Maven 集成Tomcat插件
- 637. Average of Levels in Binary Tree
- leetcode 138. Copy List with Random Pointer
- 简单说 chrome浏览器 必知必会的小技巧
- 深入解析Python中函数的参数与作用域
- 购物清单
- HTML+CSS基础课程
- mysql查询时,offset过大影响性能的原因与优化方法
- 架构设计:系统间通信(34)——被神化的ESB(上)
- Android--ExpandableListview--二级购物车简单功能实现
- 回首Java——编程思想之消息机制