LeetCode之Copy List with Random Pointer
来源:互联网 发布:软件测试工程师教程 编辑:程序博客网 时间:2024/05/17 08:04
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.
“put the nodes in the original linked list to keep track of the order”
(图片转自网络,如有侵犯,请告知)
/** * 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 == NULL) return NULL;RandomListNode *p, *q;p = head;while (p){q = p->next;RandomListNode*node=new RandomListNode(p->label);node->next = q;p->next = node;p = q;}p = head;while (p){q = p->next;q->random = (p->random?p->random->next:NULL);p = q->next;}p = head;RandomListNode *copylist = p->next;while (p->next){q = p->next;p->next = q->next;p = q;}return copylist; }};
0 0
- LeetCode之Copy List with Random Pointer
- leetcode之Copy List with Random Pointer
- leetcode 之 Copy List with Random Pointer
- leetcode之Copy List with Random Pointer
- leetcode之Copy List with Random Pointer
- LeetCode之Copy List with Random Pointer
- LeetCode之Copy List with Random Pointer
- [leetcode][list] Copy List with Random Pointer
- leetCode解题报告之Copy List with Random Pointer
- Leetcode: Copy List with Random Pointer
- LeetCode: Copy List with Random Pointer
- [LeetCode] Copy List with Random Pointer
- [leetcode]Copy List with Random Pointer
- LeetCode:Copy List with Random Pointer
- leetcode Copy List with Random Pointer
- LeetCode:Copy List with Random Pointer
- LeetCode题解:Copy List with Random Pointer
- [LeetCode]Copy List with Random Pointer
- Hibernate Search(基于version3.4)
- Windows 7安装教程(详细图解)——思齐博客
- sockaddr_in实例--连接server
- 使用CSS3线性渐变实现图片闪光划过效果
- NYOJ--C小加 之 随机数
- LeetCode之Copy List with Random Pointer
- AdapterView
- Freemarker网站静态化的实现
- 关于ListView的item高亮选择问题
- Java代码查错
- cocos2dx从win32移植到android平台。
- Hibernate各种主键生成策略与配置详解
- 理解VMWare的三种网络连接模式(bridged、NAT、host-only)
- 无法安装Windows 7的几种原因——思齐博客