由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - One question on Careercup
相关主题
看到一个题目问一道老题
求问一个题问到算法题和一道c++题
问道数组题,careercup上说无解?请问关于leetcode 里 single number II
Google 面试题 一道同学们, 看看这几行code有区别吗>
bit manipulation 小题First Missing Positive on Leetcode
Ask a amazon question from careercup.问一道(大)数据 algorithm
k-selection algorithm买书给点意见
Ask 3 M interview questionsGoogle电话面试题目
相关话题的讨论汇总
话题: careercup话题: integers话题: question话题: int话题: positive
进入JobHunting版参与讨论
1 (共1页)
o*****e
发帖数: 99
1
Given a set of positive and negative integers group all the positive
integers on one side and negative integers on one side...
numbers should be in the same order they appear....
Any O(N) algorithm without using extra space?
d*****t
发帖数: 41
2
这不就是quicksort的第一步吗?
d*****t
发帖数: 41
3
void group(int* a, int length)
{
int i=0;
int j= length-1;
while(i {
while(a[i]<0)
i++;
while(a[j]>0)
j--;
if(i {
swap(a[i], a[j]);
j--;
i++;
}
}
}
o*****e
发帖数: 99
4
quicksort doesn't work here.
"numbers should be in the same order they appear"

【在 d*****t 的大作中提到】
: void group(int* a, int length)
: {
: int i=0;
: int j= length-1;
: while(i: {
: while(a[i]<0)
: i++;
: while(a[j]>0)
: j--;

h**********d
发帖数: 4313
5
这样可以吗?
先数一下positive 的个数m
然后两个指针i, j分别从0 和 m开始,i 如果碰到负数就和 j 碰到的第一个正数对调,直
到走完

【在 o*****e 的大作中提到】
: Given a set of positive and negative integers group all the positive
: integers on one side and negative integers on one side...
: numbers should be in the same order they appear....
: Any O(N) algorithm without using extra space?

c*******t
发帖数: 1095
6
只想到用链表可以实现,用数组还没想出来
h**********d
发帖数: 4313
7
是,刚才把程序写了一下,顺序还是有问题

【在 c*******t 的大作中提到】
: 只想到用链表可以实现,用数组还没想出来
1 (共1页)
进入JobHunting版参与讨论
相关主题
Google电话面试题目bit manipulation 小题
问一道题Ask a amazon question from careercup.
Search in a sorted, rotated listk-selection algorithm
本版mj pdf合集Ask 3 M interview questions
看到一个题目问一道老题
求问一个题问到算法题和一道c++题
问道数组题,careercup上说无解?请问关于leetcode 里 single number II
Google 面试题 一道同学们, 看看这几行code有区别吗>
相关话题的讨论汇总
话题: careercup话题: integers话题: question话题: int话题: positive