avatar
Partitioning (转载)# Programming - 葵花宝典
i*0
1
【 以下文字转载自 JobHunting 讨论区 】
发信人: iq300 (iq300), 信区: JobHunting
标 题: Partitioning
发信站: BBS 未名空间站 (Wed Mar 5 17:27:35 2008)
Partitioning
Given an array of balls, which can be one of two colors (RED or BLUE), write
a function that partitions the array in-place such that on exit from the
function all the balls of the same color are contiguous. It does not matter
whether the red or blue balls come first. The return value from the function
is the index of the first ball of the second color. If there
avatar
h*e
2
这题不就是in-place sorting么,RED相当于0,BLUE相当于1。

write
matter
function

【在 i***0 的大作中提到】
: 【 以下文字转载自 JobHunting 讨论区 】
: 发信人: iq300 (iq300), 信区: JobHunting
: 标 题: Partitioning
: 发信站: BBS 未名空间站 (Wed Mar 5 17:27:35 2008)
: Partitioning
: Given an array of balls, which can be one of two colors (RED or BLUE), write
: a function that partitions the array in-place such that on exit from the
: function all the balls of the same color are contiguous. It does not matter
: whether the red or blue balls come first. The return value from the function
: is the index of the first ball of the second color. If there

avatar
c*t
3
You don't even need sorting, which would be O (nlogn). Simple
counting + swapping would be enough (O (n)).

【在 h****e 的大作中提到】
: 这题不就是in-place sorting么,RED相当于0,BLUE相当于1。
:
: write
: matter
: function

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