重新排列红,蓝和绿球阵列阵列、排列

2023-09-11 02:27:01 作者:我是一个三无女孩,没钱没活动没男友。小编今天为大家设计唯品会

在我的一次采访中,面试官问我 - 一些大小的数组包含红,蓝和绿球都混在一起随意。 像RGBBBRRGGG,其中RGB是红,绿和蓝

In one of my interviews the interviewer asked me - An array of some size contains Red, Blue and Green balls all mixed up randomly. like RGBBBRRGGG, where RGB is for Red, Green and Blue.

什么是结了喜欢 - RRRRGGGGBBBB数组最优化的方式 即所有的R的,所有的G的和所有B的在一起。

What is the most optimal way to end up with an array like- RRRRGGGGBBBB i.e. all R's, all G's and all B's together.

我建议将所有红色,蓝色,绿色他们的ASCII值,然后运行最高效的排序算法就可以了。 但他并不IM pressed。任何其他更有效的解决这个问题?以最低的空间和时间复杂度?

I proposed converting all Red, Blue, Green to their ASCII values and then running the most efficient sorting algorithm on it. But he wasn't impressed . Any other more efficient solution to this problem ? with lowest space and time complexity ?

推荐答案

只需经过阵列和计数研究的发生,

 
精彩推荐
图片推荐