Queue Reconstruction by Height
给一个2d数组, 里面是一个数字和不小于(大于等于)它的数字个数. 求一个sorted数组. 这个直接sort就可以.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
public class Solution { public int[][] reconstructQueue(int[][] people) { Arrays.sort(people, new Comparator<int[]>(){ public int compare(int[] o1, int[] o2){ if(o1[0] != o2[0]) return o2[0] - o1[0]; else return o1[1] - o2[1]; } }); List<int[]> res = new LinkedList<>(); for(int[] cur : people){ res.add(cur[1],cur); } return res.toArray(new int[people.length][]); } } |