Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4948ef4

Browse files
新增java解法中 lambda以及linkedlist.add的註釋
新增java解法中 lambda以及linkedlist.add的註釋
1 parent b8cb004 commit 4948ef4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

‎problems/0406.根据身高重建队列.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,14 @@ class Solution {
191191
public int[][] reconstructQueue(int[][] people) {
192192
// 身高从大到小排(身高相同k小的站前面)
193193
Arrays.sort(people, (a, b) -> {
194-
if (a[0] == b[0]) return a[1] - b[1];
195-
return b[0] - a[0];
194+
if (a[0] == b[0]) return a[1] - b[1];// a - b 是升序排列,故在a[0] == b[0]的狀況下,會根據k值升序排列
195+
return b[0] - a[0];//b - a 是降序排列,在a[0] != b[0],的狀況會根據h值降序排列
196196
});
197197

198198
LinkedList<int[]> que = new LinkedList<>();
199199

200200
for (int[] p : people) {
201-
que.add(p[1],p);
201+
que.add(p[1],p);//Linkedlist.add(index, value),會將value插入到指定index裡。
202202
}
203203

204204
return que.toArray(new int[people.length][]);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /