根据color 集合,对一个整形数组排序

有个enum叫做Color {Red, White, Blue}, 一个神奇的method叫Color getColor(int)
能把int value对应到Color上. 然后给一个int array, 要求sort the array to the 
order Red, White then Blue. 只能用constant memory. 如果两个数字都对应一种颜色, 
这两个数字随便怎么排. 此题我觉得是整个面试中最tricky的一道了吧. 提示是如果只有两种颜色
如何sort.

 

updated:

以前看到这道题,完全没有想法。今天又看到它,觉得本质上,这是一个类似dutch flag partition的问题。

posted @ 2011-12-01 16:19  百分百好牛  阅读(202)  评论(0编辑  收藏  举报