由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 面试题
相关主题
链表插入排序都写了一个小时,对人生失去信心了。透露两个G的onsite题
谁能帮我看下insertion sort list这道题吗?请问大牛们如何提高解决leetcode上面Linkedlist的题的能力?
一道挺简单的题给搞砸了一道linked list编程题
问个reverse linked list到底怎么了?很多面试来的居然连reverse一个链表都写不来
合并两个排序好的链表, 优解?请教一道单链表问题
弱问题,连反转链表都看不懂了Reverse LinkedList II 怎样一遍写对啊?
弱问一个小问题,leetcode 上merge sorted list关于priority_queue一问
问一个merge K sorted list的时间复杂度请教iterative merge sort list的代码
相关话题的讨论汇总
话题: iter话题: curr话题: list话题: next话题: unsort
进入JobHunting版参与讨论
1 (共1页)
m********7
发帖数: 1368
1
面试让用iterative method写一个 in place insertion sort with singly linked
list..哎好久没有练,写了半小时还有BUG。。一般大家写这样难度的多久可以写到BUG
FREE?
d**********x
发帖数: 4083
2
1 day
remember what is the INVARIANT in your loop. maintain it and you will win

BUG

【在 m********7 的大作中提到】
: 面试让用iterative method写一个 in place insertion sort with singly linked
: list..哎好久没有练,写了半小时还有BUG。。一般大家写这样难度的多久可以写到BUG
: FREE?

c********p
发帖数: 1969
3
mark
m********7
发帖数: 1368
4
我也觉得这不是几十分钟能搞定的吧。。
thanks for the tip!!

【在 d**********x 的大作中提到】
: 1 day
: remember what is the INVARIANT in your loop. maintain it and you will win
:
: BUG

l********n
发帖数: 1038
5
这里循环不变量 是什么,大牛讲讲循环不变量怎么找。我怎么感觉循环不变量这个概
念更像是验证程序对不对用的
d**********x
发帖数: 4083
6
think about one implementation for partition in quick sort.
keeping one pointer to point to the end of the numbers which are smaller
than the pivot is the key to write correct algorithm

【在 l********n 的大作中提到】
: 这里循环不变量 是什么,大牛讲讲循环不变量怎么找。我怎么感觉循环不变量这个概
: 念更像是验证程序对不对用的

l********n
发帖数: 1038
7
多问一句,那这道题的invariant是什么

【在 d**********x 的大作中提到】
: think about one implementation for partition in quick sort.
: keeping one pointer to point to the end of the numbers which are smaller
: than the pivot is the key to write correct algorithm

d**********x
发帖数: 4083
8
for insertion sort
keep one pointer pointing to the last sorted element. the 'invariant' is,
before and at this point, all elements are sorted.
starting with this idea i hope you can think more clear...though it looks
like not that helpful at first glance

【在 l********n 的大作中提到】
: 多问一句,那这道题的invariant是什么
r*******n
发帖数: 3020
9
这个题有点意思。
ListNode* insert(ListNode* head){
if(head==NULL)
return;
ListNode* curr=head->next;
ListNode* dummyHead= new ListNode(0);
dummyHead->next=head;
while(curr!=NULL){
ListNode* pre=dummyHead;
// Find where to insert
while(p!=curr){
if(p->val>=curr->val)
break;
pre=p;
p=p->next;
}
if(p==curr){
//curr's value is largest so far
curr=curr->next;
}else{
//detach curr node and insert it behind of node pre
ListNode* t = curr->next;
curr->next=p;
pre->next=curr;
curr=t;
}
}
ListNode* newHead=dummyHead->next;
delete dummyHead;
return newHead;
}


BUG

【在 m********7 的大作中提到】
: 面试让用iterative method写一个 in place insertion sort with singly linked
: list..哎好久没有练,写了半小时还有BUG。。一般大家写这样难度的多久可以写到BUG
: FREE?

m********7
发帖数: 1368
10
和我这个很相似。。大牛写了多久?
List * inPlaceInsertionSort(List *head){
if(!head) throw(“empty list”);
// assume head is sorted, and unsort is unsorted
List *unsort = head->next;
while(unsort){
// take the front element from unsort
List *prev = NULL;
List *iter = head;
List *key = unsort;
// iterate within sorted list
while(iter){
if(iter->data < key->data){
prev = iter;
iter = iter->next;
}
else
break;
}
// if iter reaches end of sorted list, then sort the next node
unsort = unsort->next;
if(iter==key)
continue;
// mark the place where to insert key
List *place = iter;
// move iter to the end of sorted list and connnect to new unsort
while(iter->next!=key)
iter=iter->next;
iter->next = unsort;
// insert key to place
if(prev==NULL)
head = key;
else
prev->next = key;
key->next = place;
}
return head;
}
e*******s
发帖数: 1979
11
一两个礼拜吧

BUG

【在 m********7 的大作中提到】
: 面试让用iterative method写一个 in place insertion sort with singly linked
: list..哎好久没有练,写了半小时还有BUG。。一般大家写这样难度的多久可以写到BUG
: FREE?

1 (共1页)
进入JobHunting版参与讨论
相关主题
请教iterative merge sort list的代码合并两个排序好的链表, 优解?
M家 onsite 悲剧,同胞们弄死烙印吧弱问题,连反转链表都看不懂了
leetcode上这个链表节点的定义是什么意思?ListNode(int x) : val(x), next(NULL) {}弱问一个小问题,leetcode 上merge sorted list
怎么理解递归解决的“swap every two elements in a linked list”?问一个merge K sorted list的时间复杂度
链表插入排序都写了一个小时,对人生失去信心了。透露两个G的onsite题
谁能帮我看下insertion sort list这道题吗?请问大牛们如何提高解决leetcode上面Linkedlist的题的能力?
一道挺简单的题给搞砸了一道linked list编程题
问个reverse linked list到底怎么了?很多面试来的居然连reverse一个链表都写不来
相关话题的讨论汇总
话题: iter话题: curr话题: list话题: next话题: unsort