输入一个复杂链表(每个节点中有节点值,以及两个指针,一个指向下一个节点,另一个特殊指针指向任意一个节点)。一开始想这道题毫无思路,如果蛮来,首先创建好正常的链表,然后考虑sibling这个分量,则需要O(n^2)的时间复杂度,然后一个技巧便可以巧妙的解答此题。看图便知。首先是原始的链表然后我们还是首...
分类:
其他好文 时间:
2015-08-29 00:47:48
阅读次数:
184
题目:
实现函数ComplexListNode* Clone(ComplexListNode*
pHead), 复制一个复杂链表.在复杂链表中,每个结点除了有一个m_pNext指针指向下一个结点外,还有一个m_pSibling指向链表中的任意结点或者NULL.结点定义如下:
struct ComplexListNode
{
int m...
分类:
其他好文 时间:
2015-08-25 21:37:51
阅读次数:
167
【138-Copy List with Random Pointer(拷贝有随机指针的单链表)】【LeetCode-面试算法经典-Java实现】【所有题目目录索引】原题 A linked list is given such that each node contains an additional random pointer which could point to any node in t...
分类:
编程语言 时间:
2015-08-18 07:55:06
阅读次数:
164
看下面一个链表结点的定义:struct ComplexListNode{ int val; struct ComplexListNode *next; struct ComplexListNode *sibling; ComplexListNode(int x) : val(x), next(NU....
分类:
其他好文 时间:
2015-08-09 00:16:37
阅读次数:
190
#include
using namespace std;
#define Default -1
struct Node
{
int data;
Node *next;
Node *other;//这是复杂链表的额外的一个指针,指向一个指定位置的节点。
Node(int d = int()) :data(d), next(NULL), other...
分类:
编程语言 时间:
2015-07-30 21:33:46
阅读次数:
204
题目:
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.
解题:
这题是要复制一个链表,这个链表比...
分类:
编程语言 时间:
2015-07-28 23:17:43
阅读次数:
583
新的解决方案:#ifndef COMPLEX_LISTCLONE_H#define COMPLEX_LISTCLONE_H#includestruct ComplexListNode{ int m_nValue; struct ComplexListNode *m_pNext; struct Com...
分类:
其他好文 时间:
2015-07-17 20:43:21
阅读次数:
196
转载请注明出处:http://blog.csdn.net/ns_code/article/details/26154691题目描写叙述:输入一个复杂链表(每一个节点中有节点值,以及两个指针,一个指向下一个节点,还有一个特殊指针指向随意一个节点)。输入:输入可能包括多个測试例子,输入以EOF结束。对于...
分类:
其他好文 时间:
2015-07-16 11:29:25
阅读次数:
168
解法一:
解法二:
void CloneNodes(ComplexListNode* pHead)
{
ComplexListNode* pNode = pHead;
while (pNode != NULL)
{
ComplexListNode* pCLoned = new ComplexListNode();
pCloned->m_nValue = pN...
分类:
其他好文 时间:
2015-07-09 16:18:28
阅读次数:
103
中等 复制带随机指针的链表
查看运行结果
27%
通过
给出一个链表,每个节点包含一个额外增加的随机指针可以指向链表中的任何节点或空的节点。
返回一个深拷贝的链表。
用了一个哈希表,空间换取时间
/**
* Definition for singly-linked list with a random pointer.
* ...
分类:
其他好文 时间:
2015-07-09 14:40:58
阅读次数:
131