Skip to content

Commit

Permalink
Merge pull request youngyangyang04#2091 from Lozakaka/patch-13
Browse files Browse the repository at this point in the history
新增java解法中 lambda以及linkedlist.add的註釋
  • Loading branch information
youngyangyang04 authored Jun 2, 2023
2 parents 6156804 + 4948ef4 commit 80cb527
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions problems/0406.根据身高重建队列.md
Original file line number Diff line number Diff line change
Expand Up @@ -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][]);
Expand Down

0 comments on commit 80cb527

Please sign in to comment.