mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-21 02:56:11 +00:00
build
This commit is contained in:
@@ -276,7 +276,7 @@ comments: true
|
||||
for (int num in nums) {
|
||||
m = max(m, num);
|
||||
}
|
||||
// 2. 统计各数字的出现次数
|
||||
// 2. 统计各数字的出现次数
|
||||
// counter[num] 代表 num 的出现次数
|
||||
List<int> counter = List.filled(m + 1, 0);
|
||||
for (int num in nums) {
|
||||
@@ -728,7 +728,7 @@ $$
|
||||
for (int i = n - 1; i >= 0; i--) {
|
||||
int num = nums[i];
|
||||
res[counter[num] - 1] = num; // 将 num 放置到对应索引处
|
||||
counter[num]--; // 令前缀和自减 1 ,得到下次放置 num 的索引
|
||||
counter[num]--; // 令前缀和自减 1 ,得到下次放置 num 的索引
|
||||
}
|
||||
// 使用结果数组 res 覆盖原数组 nums
|
||||
nums.setAll(0, res);
|
||||
|
||||
Reference in New Issue
Block a user