mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-07 15:45:40 +08:00
Merge pull request #2091 from Lozakaka/patch-13
新增java解法中 lambda以及linkedlist.add的註釋
This commit is contained in:
@ -191,14 +191,14 @@ class Solution {
|
||||
public int[][] reconstructQueue(int[][] people) {
|
||||
// 身高从大到小排(身高相同k小的站前面)
|
||||
Arrays.sort(people, (a, b) -> {
|
||||
if (a[0] == b[0]) return a[1] - b[1];
|
||||
return b[0] - a[0];
|
||||
if (a[0] == b[0]) return a[1] - b[1]; // a - b 是升序排列,故在a[0] == b[0]的狀況下,會根據k值升序排列
|
||||
return b[0] - a[0]; //b - a 是降序排列,在a[0] != b[0],的狀況會根據h值降序排列
|
||||
});
|
||||
|
||||
LinkedList<int[]> que = new LinkedList<>();
|
||||
|
||||
for (int[] p : people) {
|
||||
que.add(p[1],p);
|
||||
que.add(p[1],p); //Linkedlist.add(index, value),會將value插入到指定index裡。
|
||||
}
|
||||
|
||||
return que.toArray(new int[people.length][]);
|
||||
|
Reference in New Issue
Block a user