138. Copy List with Random Pointer
来源:互联网 发布:粉尘检测数据 编辑:程序博客网 时间:2024/05/16 17:18
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.
Subscribe to see which companies asked this question
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 == NULL) return head; RandomListNode *p = head; while(p != NULL) { RandomListNode *q = new RandomListNode(p->label); q->random = p->random; q->next = p->next; p->next = q; p = p->next->next; } p = head; while(p != NULL) { if(p->random != NULL) { p->next->random = p->random->next; } p = p->next->next; } RandomListNode *ret = new RandomListNode(0); ret->next = head; RandomListNode *q = ret; p = head; while(p != NULL) { q->next = p->next; p->next = q->next->next; q = q->next; p = p->next; } return ret->next; }};
0 0
- 138. Copy List with Random Pointer
- LeetCode 138. Copy List with Random Pointer
- [Leetcode] 138. Copy List with Random Pointer
- 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
- 138. Copy List with Random Pointer
- LeetCode 138. Copy List with Random Pointer
- 138. Copy List with Random Pointer
- leetcode.138. Copy List with Random Pointer
- 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
- 138. Copy List with Random Pointer
- [LeetCode] 138. Copy List with Random Pointer
- Android 长按Listview显示CheckBox,实现批量删除【转】
- Docker多容器部署
- Android权限汇集
- Android中的Adapter 详解(一)
- 操作系统的相关计算题
- 138. Copy List with Random Pointer
- 单片机上课笔记
- 树莓派使用USB摄像头和motion实现监控
- Think in Java中多线程所接触到且需要学习的类和接口
- Swift之?和!
- 数据类型的封装
- CFF201604-2俄罗斯方块
- 开发日志:freemark微信网站架构思路
- androidannotations出现生成的类找不到