package leetcode;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/rank-transform-of-an-array/
 */
public class Problem1331 {
    public int[] arrayRankTransform(int[] arr) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem1331 prob = new Problem1331();
        System.out.println(Arrays.toString(prob.arrayRankTransform(new int[]{40,10,20,30}))); // [4,1,2,3]
        System.out.println(Arrays.toString(prob.arrayRankTransform(new int[]{100,100,100}))); // [1,1,1]
        System.out.println(Arrays.toString(prob.arrayRankTransform(new int[]{37,12,28,9,100,56,80,5,12}))); // [5,3,4,2,8,6,7,1,3]
    }
}

@@ -29,22 +29,93 @@
 va.util.
-Arrays
+HashMap;%0Aimport java.util.Map;%0Aimport java.util.Set;%0Aimport java.util.TreeSet
 ;%0A%0A/**%0A 
@@ -266,477 +266,482 @@
     
-// TODO%0A        return null;
+Set%3CInteger%3E set = new TreeSet%3C%3E();%0A        for (int i = 0; i %3C arr.length; i++) %7B
 %0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem1331 prob = new Problem1331();%0A        System.out.println(Arrays.toString(prob.arrayRankTransform(new int%5B%5D%7B40,10,20,30%7D))); // %5B4,1,2,3%5D%0A        System.out.println(Arrays.toString(prob.arrayRankTransform(new int%5B%5D%7B100,100,100%7D))); // %5B1,1,1%5D%0A        System.out.println(Arrays.toString(prob.arrayRankTransform(new int%5B%5D%7B37,12,28,9,100,56,80,5,12%7D))); // %5B5,3,4,2,8,6,7,1,3%5D
+    set.add(arr%5Bi%5D);%0A        %7D%0A        int rank = 1;%0A        Map%3C/* value= */ Integer, /* rank= */ Integer%3E map = new HashMap%3C%3E();%0A        for (int n : set) %7B%0A            map.put(n, rank);%0A            rank++;%0A        %7D%0A        int%5B%5D answer = new int%5Barr.length%5D;%0A        for (int i = 0; i %3C arr.length; i++) %7B%0A            answer%5Bi%5D = map.get(arr%5Bi%5D);%0A        %7D%0A        return answer;
 %0A   

Solve problem 1331