class Solution {
public int[] arrayRankTransform(int[] arr) {
if (arr == null || arr.length == 0){
return new int[]{};
}
int[] res = arr.clone();
Map<Integer, Integer> map = new HashMap<>();
Arrays.sort(arr);
int index = 1;
for (int i : arr) {
if (!map.containsKey(i)){
map.put(i, index++);
}
}
for (int i = 0; i < res.length; i++){
res[i] = map.get(res[i]);
}
return res;
}
}