boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 问了一个链表,1->2->3->4->5, 每两个交换,2->1->4->3->5,
相关主题
问了一个链表,1->2->3->4->5, 每两个交换,2->1->4->3->5
面试面试官错了怎么办?
弱问题,连反转链表都看不懂了
java 链表里面dummy node 一问?谢谢
一个Linkedlist面试题的教训
【我自己写的LinkedList为什么总有错?】
amazon onsite 面经
再问大牛们leetcode上面Linkedlist的题,Reverse Nodes in k-G
array 转换成 linkedlist, 在线等, 挺急的--help is still nee
ms面试题目
相关话题的讨论汇总
话题: 链表话题: tmp话题: node话题: head话题: 交换
进入JobHunting版参与讨论
1 (共1页)
c*******r
发帖数: 309
1
要求interative和recursive.
这个应该怎么写啊,java的话~~linkedlist真是把我搞死了.....
p*****2
发帖数: 21240
2
两两交换应该比昨天那个N交换要容易写很多吧?
p*****2
发帖数: 21240
3
我昨天写了个N的,不过还没写完。没有考虑到不能被N整除的情况。
int Reverse(Node** head, int n)
{
Node* tmphead=null;
int i=0;
Node* tmp=*head;
Node* first=tmp;
while(tmp)
{
if(i==0)
first=tmp;
i++;
if(i==n)
{
tmp->next=tmphead;
tmphead=first;
i=0;
}
tmp=tmp->next;
}
if(i!=0)
{
return -1;
}
*head=tmphead;

return 0;
}
int ReverseList(Node** head, int n)
{
if(head==NULL || *head==NULL || n<0)
return -1;
if(n==0 || n==1)
return 0;
if(!Reverse(head,1))
return -2;
if(!Reverse(head,n))
return -2;
}
1 (共1页)
进入JobHunting版参与讨论
相关主题
ms面试题目
Reverse LinkedList II 怎样一遍写对啊?
reverse linked list 问题, double 和 single 的不同
"简单的"linklist的问题
Print a binary tree in level order but starting from leaf node up to root
有人同看Populating Next Right Pointers in Each Node II的recursive写法么?
delete a node in linked list
[合集] 链表reverse得最简洁算法
我恨iPhone@Facebook电面
问一道常见面试题,reverse a linked list
相关话题的讨论汇总
话题: 链表话题: tmp话题: node话题: head话题: 交换