由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - copy link with random additional pointers
相关主题
请教下copy list with random pointer有人同看Populating Next Right Pointers in Each Node II的recursive写法么?
Populating Next Right Pointers in Each Node IIPopulating Next Right Pointers in Each Node II
leetcode populating next pointer 2想成为嵌入式程序员应知道的0x10个基本问题 zz
sorted linked list里insert一个node哪位大侠帮我看看这个code
reverse random pointers of a single linked listLeetcode新题 Copy List with Random Pointer
How can one determine whether a singly linked list has a cycle?Leetcode Copy List with Random Pointer Runtime Error?
今天计划做20题求救! Copy List With Random Pointer总是超时
leetcode Copy List with Random Pointer各位刷友,leetcode里的题目:Copy List with Random Pointer
相关话题的讨论汇总
话题: next话题: pointers话题: random话题: additional话题: null
进入JobHunting版参与讨论
1 (共1页)
c***2
发帖数: 838
1
复制linked list。 已知每个节点有两个pointer,一个指向后一个节点,另一个指向
其他任意一节点。 O(n)时间内,无附加内存,复制该linked list。(存储不连续)
s*******e
发帖数: 93
2
I saw this problem earlier here. The answer is:
(imagine you have a->b->c->d, lets call the other pointer as "other"
1. duplicate each node and insert after itself. Now you get a->a->b->b->c->c->d->d
2. node n=head
while(n!=null)
n->next->other = n->other->next
n=n->next->next
3. separate the two lists
head2 = head->next
node n=head
while(n->next->next !=null)
n->next->next = n->next->next->next
n->next = n->next->next
n=n->next
n->next = null
n->next->next = null
不知道implement有没有错,不过idea就是这样
c***2
发帖数: 838
3
very good idea.
1) First pass: duplicate each node
2) Second pass: populate new other pointers
3) Third pass: split the list
Thanks!
h**********d
发帖数: 4313
1 (共1页)
进入JobHunting版参与讨论
相关主题
各位刷友,leetcode里的题目:Copy List with Random Pointerreverse random pointers of a single linked list
copy list with random pointer 老出错How can one determine whether a singly linked list has a cycle?
微软面经今天计划做20题
remove a node (and its memory) from a doubly linked listleetcode Copy List with Random Pointer
请教下copy list with random pointer有人同看Populating Next Right Pointers in Each Node II的recursive写法么?
Populating Next Right Pointers in Each Node IIPopulating Next Right Pointers in Each Node II
leetcode populating next pointer 2想成为嵌入式程序员应知道的0x10个基本问题 zz
sorted linked list里insert一个node哪位大侠帮我看看这个code
相关话题的讨论汇总
话题: next话题: pointers话题: random话题: additional话题: null