由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 求问一个题
相关主题
Ask 3 M interview questions请教一道题目
请教一道CS常见题的解法问一个面试题
Google电话面试题目Given an int array and an int value. Find all pairs in arr
Given an array of N integers from range [0, N] and one is missing. Find the missing number.这个怎么弄?
问一道面试题目问一道老题
One question on Careercup请教一个题目
G家onsite 随机数一题请教一道L的题
请教一个数论的问题彭博 面试题
相关话题的讨论汇总
话题: integers话题: given话题: nums话题: array话题: negative
进入JobHunting版参与讨论
1 (共1页)
c**i
发帖数: 306
1
Given an array of positive and negative integers, re-arrange it so that you
have positive integers on one end and negative integers on other, but retain
their order of appearance in the original array.
For example, given [1, 7, -5, 9, -12, 15]
The answer would be: [-5, -12, 1, 7, 9, 15]
This should be done in O(n) time and O(1) space.
h*********2
发帖数: 444
2
想了半天没想出来
Google了一下,发现这篇paper是说这个的
http://link.springer.com/article/10.1007%2FBF01994842
h***k
发帖数: 161
3
扫第一遍记录有多少个负数,作为正数starting index,扫第二遍two pointers不就完
了?
h***k
发帖数: 161
4
看错了。。是O(n) space的解法
c***r
发帖数: 280
5
要求in-place吗? 如果不能再建一个array,想不出O(n)时间,O(1)空间的解法啊。

you
retain

【在 c**i 的大作中提到】
: Given an array of positive and negative integers, re-arrange it so that you
: have positive integers on one end and negative integers on other, but retain
: their order of appearance in the original array.
: For example, given [1, 7, -5, 9, -12, 15]
: The answer would be: [-5, -12, 1, 7, 9, 15]
: This should be done in O(n) time and O(1) space.

c*****m
发帖数: 271
6
难道不就是quicksort里面的partition么?求拍
r****7
发帖数: 2282
7
顺序会改变

【在 c*****m 的大作中提到】
: 难道不就是quicksort里面的partition么?求拍
p****6
发帖数: 3
8
my answer of C++ version. This question actually is a partial of the
quicksort method.
void reorder(vector& nums)
{
int len = nums.size();
int start = -1;
for(int i = 0; i < len; i++)
{
if(nums[i] < 0)
swap(nums[i], nums[++start]);
}
}
1 (共1页)
进入JobHunting版参与讨论
相关主题
彭博 面试题问一道面试题目
TripAdvsior 面经 (完败)One question on Careercup
好挫的F家面经G家onsite 随机数一题
C++ 程序求助请教一个数论的问题
Ask 3 M interview questions请教一道题目
请教一道CS常见题的解法问一个面试题
Google电话面试题目Given an int array and an int value. Find all pairs in arr
Given an array of N integers from range [0, N] and one is missing. Find the missing number.这个怎么弄?
相关话题的讨论汇总
话题: integers话题: given话题: nums话题: array话题: negative