public class Solution21050101 { public static void main(String[] args) { // test1 int[] nums = {1, 2, 1}; int[] scores = {67, 58, 89, 42, 27}; int[][] preference = {{0, 1}, {1}, {0, 2}, {2}, {0}}; Solution21050101 obj = new Solution21050101(); System.out.println(Arrays.toString(obj.departmentRecruit(nums, scores, preference))); } public int[] departmentRecruit(int[] nums, int[] scores, int[][] preference) { // 需要定义两个排序数组 Integer[] sorted1 = new Integer[scores.length]; for (int i = 0; i < scores.length; i++) { sorted1[i] = i; } // 对sorted1进行排序,sorted2就是排序后的不规则二维数组 Arrays.sort(sorted1, (o1, o2) -> scores[o2] - scores[o1]); int[][] sorted2 = new int[preference.length][]; for (int i = 0; i < preference.length; i++) { sorted2[i] = preference[sorted1[i]]; } return new int[] {}; } }
Java第二个数组根据第一个数组进行排序
最新推荐文章于 2024-08-18 21:36:31 发布