๐ 406. ๆ นๆฎ่บซ้ซ้ๅปบ้ๅ
2022ๅนด10ๆ10ๆฅ
- algorithm
๐ 406. ๆ นๆฎ่บซ้ซ้ๅปบ้ๅ
้พๅบฆ: ๐
้ฎ้ขๆ่ฟฐ
่งฃๆณ
class Solution {
public int[][] reconstructQueue(int[][] people) {
// ๆ่ทฏ๏ผ
// ๆฐ็ปๆๅบ - ๆ นๆฎ่บซ้ซ้ๅบ๏ผ่บซ้ซ็ธๅๆ นๆฎ ๆๅ ๅๅบ
// ไพๆฌกๆ นๆฎๆๅๆๅ
ฅๅฐ้พ่กจไธญ
Arrays.sort(people, (a, b) -> {
if(a[0] == b[0]) {
return a[1] - b[1];
} else {
return b[0] - a[0];
}
});
ArrayList<int[]> list = new ArrayList<>();
int len = people.length;
for(int i = 0; i < len; i ++) {
int[] cur = people[i];
int height = cur[0];
int index = cur[1];
// System.out.println(Arrays.toString(cur));
list.add(index, cur);
}
int[][] res = new int[len][2];
for(int i = 0; i < len; i ++) {
res[i] = list.get(i);
}
return res;
}
}