Skip to content

Commit d95f037

Browse files
author
tianqing.liang
committed
计数排序修改
1 parent 5c88863 commit d95f037

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

22-CountingSort-And-RadixSort/Main.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,13 @@ void main() {
5555
int R = 101;
5656

5757
// O(n)
58-
List cnt = List.filled(R, int, growable: true);
59-
for (Student student in students) cnt[student.getScore()!]++;
58+
List cnt = List.filled(R, 0, growable: true);
59+
for (Student student in students) {
60+
cnt[student.getScore()!] = cnt[student.getScore()!] +1;
61+
};
6062

6163
// O(R)
62-
List index = List.filled(R + 1, int, growable: true);
64+
List index = List.filled(R + 1, 0, growable: true);
6365
for (int i = 0; i < R; i++) index[i + 1] = index[i] + cnt[i];
6466

6567
// O(n)

22-CountingSort-And-RadixSort/Solution.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class Solution {
22
sortColors(List<int> nums) {
3-
List? cnt = List.filled(3, int, growable: true);
3+
List? cnt = List.filled(3, 0, growable: true);
44
for (int num in nums!) {
55
cnt[num]++;}
66

@@ -19,7 +19,7 @@ class Solution {
1919
// 处理元素取值范围是 [0, R) 的计数排序
2020
int R = 3;
2121

22-
List? cnt = List.filled(3, int, growable: true);
22+
List? cnt = List.filled(3, 0, growable: true);
2323
for (int num in nums!) {
2424
cnt[num]++;
2525
}

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# AlgorithmAndDataArchitecture
22

3-
## 介绍
43
<h2>使用Dart语言重写数据结构与算法</h2>
54

65
1. 线性搜索

0 commit comments

Comments
 (0)