How to find the permutation of a sort in Java

后端 未结 5 1168
攒了一身酷
攒了一身酷 2021-01-11 22:41

I want to sort an array and find the index of each element in the sorted order. So for instance if I run this on the array:

[3,2,4]

I\'d ge

5条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-11 23:39

    import java.util.*;
    public class Testing{
       public static void main(String[] args){
           int[] arr = {3, 2, 4, 6, 5};
           TreeMap map = new TreeMap();
           for(int i = 0; i < arr.length; i++){
                map.put(arr[i], i);
           }
           System.out.println(Arrays.toString(map.values().toArray()));
       }
    }
    

提交回复
热议问题