avatar
c*a
2
是不是shuffle打乱链表啊
copy a linked list where the data member of each node in the linked list
could be any other node in the linked list.
avatar
l*a
4
linked list有一个指针data member,可能指向这个连表中任意结点

【在 c*****a 的大作中提到】
: 是不是shuffle打乱链表啊
: copy a linked list where the data member of each node in the linked list
: could be any other node in the linked list.

avatar
v*n
5
pp is not clear
avatar
j*y
6
struct Node
{
Node * next;
Node * node;
}
copy this linked list

【在 c*****a 的大作中提到】
: 是不是shuffle打乱链表啊
: copy a linked list where the data member of each node in the linked list
: could be any other node in the linked list.

avatar
M*5
8
写了个c++版本的,O(n)的time efficiency和O(n)的space efficiency,不知道有没有
更优化的?比如no extra space and only one time walk-through?
struct Node{
Node* data;
Node* next;
};
Node* copyLinkedList(Node* head){
if(!head)
return NULL;

std::map node_map;
Node* new_head = copyLinkedListHelper(head, node_map);

Node* cur = new_head;
while(head){
cur->node = node_map[head->node];
cur = cur->next;
head = head->next;
}
return new_head;
}
Node* copyLinkedListHelper(Node* head, std::map& n_map){
if(!head)
return NULL;

Node* n = new Node;
n_map[head] = n;
n->next = copyLinkedListHelper(head->next, n_map);

return n;
}
avatar
k*r
9
幸好ld不去鹊桥,这样的mm就是他想要的梦中情人啊,靠

【在 l*******n 的大作中提到】
: 这个是小兰,还是新蛋
avatar
c*a
10
写出来了
public static ListNode copyLink(ListNode node){
ListNode original = node, head = null, newOne=null,next;
//insert node inbetween, so abc becomes aabbcc
while(original!=null){
newOne = new ListNode(original.val);
next = original.next;
original.next = newOne;
newOne.next =next;
original = next;
}
//new list
head = node.next;
//copying random link
original = node;
while(original!=null){
original.next.datamember = original.datamember.next;
original = original.next.next;
}
//separte two lists out
original = node;
newOne = original.next;
while(original!=null && newOne!=null){
next = newOne.next;
if(next!=null){
original.next= next;
newOne.next = next.next;
newOne = newOne.next;
}
original = next;
}
return head;
}
avatar
k*8
11
不知道为什么要贴这种看不清楚脸的照片去征婚
avatar
M*5
12
这个idea很好,duplicate linked list,估计我要是在phone interview的时候这么写
肯定会出bug,但是这在space上应该是很优化的

【在 c*****a 的大作中提到】
: 写出来了
: public static ListNode copyLink(ListNode node){
: ListNode original = node, head = null, newOne=null,next;
: //insert node inbetween, so abc becomes aabbcc
: while(original!=null){
: newOne = new ListNode(original.val);
: next = original.next;
: original.next = newOne;
: newOne.next =next;
: original = next;

avatar
y*u
13
我觉得我会拿着这个另克去卖钱

【在 k****r 的大作中提到】
: 幸好ld不去鹊桥,这样的mm就是他想要的梦中情人啊,靠
avatar
y*9
14
这道题貌似超有名 前段时间有人发过 没看过答案写最优解我觉得很难啊
avatar
k*r
15
晚了,他已经被我罩住了

【在 y*****u 的大作中提到】
: 我觉得我会拿着这个另克去卖钱
avatar
M*5
16
最优解是不是就是lz发的这个?如果是的我觉得这个要当场写的bugfree确实不容易。
。。

【在 y********9 的大作中提到】
: 这道题貌似超有名 前段时间有人发过 没看过答案写最优解我觉得很难啊
avatar
C*g
17
“想征一个男人,到世界上最美的海滩看日落,到世界上最大的图书馆自习...”
wk,到海滩不赶紧挖点蚌壳架个锅煮了吃,竟然浪费时间看日落。。。
btw弱弱地问世界上最大的图书馆是哪个@@?

这个是小兰,还是新蛋

【在 l*******n 的大作中提到】
: 这个是小兰,还是新蛋
avatar
H*s
18
对!这个就是标准答案。

【在 M********5 的大作中提到】
: 最优解是不是就是lz发的这个?如果是的我觉得这个要当场写的bugfree确实不容易。
: 。。

avatar
r*9
19
有coupon没?
avatar
j*2
20
哪家的店面问过啊?

【在 M********5 的大作中提到】
: 这个idea很好,duplicate linked list,估计我要是在phone interview的时候这么写
: 肯定会出bug,但是这在space上应该是很优化的

avatar
e*e
21
难道不是你们佛学院的?

【在 C****g 的大作中提到】
: “想征一个男人,到世界上最美的海滩看日落,到世界上最大的图书馆自习...”
: wk,到海滩不赶紧挖点蚌壳架个锅煮了吃,竟然浪费时间看日落。。。
: btw弱弱地问世界上最大的图书馆是哪个@@?
:
: 这个是小兰,还是新蛋

avatar
c*t
22
赞,问一下,最后一次拆分循环
条件 while(original!=null && newOne!=null), 可不可以改为while(original!=
null)什么情况original不是null, newOne为null?

【在 c*****a 的大作中提到】
: 写出来了
: public static ListNode copyLink(ListNode node){
: ListNode original = node, head = null, newOne=null,next;
: //insert node inbetween, so abc becomes aabbcc
: while(original!=null){
: newOne = new ListNode(original.val);
: next = original.next;
: original.next = newOne;
: newOne.next =next;
: original = next;

avatar
y*u
23
罩不罩是你的事
卖另克是俺的事
hiahia

【在 k****r 的大作中提到】
: 晚了,他已经被我罩住了
avatar
W*t
24
猪!

【在 C****g 的大作中提到】
: “想征一个男人,到世界上最美的海滩看日落,到世界上最大的图书馆自习...”
: wk,到海滩不赶紧挖点蚌壳架个锅煮了吃,竟然浪费时间看日落。。。
: btw弱弱地问世界上最大的图书馆是哪个@@?
:
: 这个是小兰,还是新蛋

avatar
C*g
25

被发现了。。。。。。。。。

猪!

【在 W*****t 的大作中提到】
: 猪!
avatar
C*g
26
诶你欠的包子呢?

猪!

【在 W*****t 的大作中提到】
: 猪!
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。