大小为n的数组排序 [英] sort array of size n

查看:122
本文介绍了大小为n的数组排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果大小为n的阵列仅具有3个值0,1和2(重复任何次数)什么是对它们进行排序的最佳方式。最好的指示的复杂性。考虑空间和时间复杂度都

if an array of size n has only 3 values 0 ,1 and 2 (repeated any number of times) what is the best way to sort them. best indicates complexity. consider space and time complexity both

推荐答案

计数每个数字的OCCURENCES并随后填写了正确的计数的数组,这是 O(N)

Count the occurences of each number and afterward fill the array with the correct counts, this is O(n)

这篇关于大小为n的数组排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆