11.8---维护x的秩(CC150)

思路:比较easy。就是借助hashset让他有序然后就能够比较节省时间了。

答案:

    
    public static int[] getRankOfNumber(int[] a, int n){
        int[] res = new int[n];
        HashSet<Integer> hash = new HashSet();
        for(int i = 0; i < n;i++){
            int num = 0;
            for(int tmp : hash){
                if(tmp <= a[i]){
                    num++;
                }
            }
            hash.add(a[i]);
            res[i] = num;
        }
        
        
        
        
        return res;
    }
View Code

 

posted @ 2016-01-05 11:46  创业-李春跃-增长黑客  阅读(162)  评论(0编辑  收藏  举报