你的位置:首页 > 软件开发 > Java > Lintcode: Sort Colors II

Lintcode: Sort Colors II

发布时间:2015-04-06 10:03:43
Given an array of n objects with k different colors (numbered from 1 to k), sort them so that objects of the same color are adjacent, with t ...
Given an array of n objects with k different colors (numbered from 1 to k), sort them so that objects of the same color are adjacent, with the colors in the order 1, 2, ... k.NoteYou are not suppose to use the library's sort function for this problem.ExampleGIven colors=[3, 2, 2, 1, 4], k=4, your code should sort colors in-place to [1, 2, 2, 3, 4]. ChallengeA rather straight forward solution is a two-pass algorithm using counting sort. That will cost O(k) extra memory.Can you do it without using extra memory?

原标题:Lintcode: Sort Colors II

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录