Open youngyangyang04 opened 3 months ago
Arrays.sort(people, (a, b) -> {
a[0] == b[0] ? a[1] - b[1] : b[0] - a[0]
});
List<int[]> q = new LinkedList<>();
for (int[] p : people) {
q.add(p[1], p);
}
return q.toArray(new int[q.size()][]);
// 例: people = [[7,0],[4,4],[7,1],[5,0],[6,1],[5,2]]
sort 排序后: people = [[7,0],[7,1],[6,1],[5,0],[5,2],[4,4]]
for 循环后: q = [[5,0],[7,0],[5,2],[6,1],[4,4],[7,1]]
https://www.programmercarl.com/0406.%E6%A0%B9%E6%8D%AE%E8%BA%AB%E9%AB%98%E9%87%8D%E5%BB%BA%E9%98%9F%E5%88%97.html