TreeMap默认是按key从高到低排序的,所以对其重构时o2 - o1就是从小到大排序了
TreeMap<Integer, Integer> treeMap = new TreeMap<>(new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
return o2 - o1;
}
});
2024-03-04 16:35:35
TreeMap默认是按key从高到低排序的,所以对其重构时o2 - o1就是从小到大排序了
TreeMap<Integer, Integer> treeMap = new TreeMap<>(new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
return o2 - o1;
}
});