File tree Expand file tree Collapse file tree 3 files changed +7
-6
lines changed
22-CountingSort-And-RadixSort Expand file tree Collapse file tree 3 files changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -55,11 +55,13 @@ void main() {
55
55
int R = 101 ;
56
56
57
57
// 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
+ };
60
62
61
63
// O(R)
62
- List index = List .filled (R + 1 , int , growable: true );
64
+ List index = List .filled (R + 1 , 0 , growable: true );
63
65
for (int i = 0 ; i < R ; i++ ) index[i + 1 ] = index[i] + cnt[i];
64
66
65
67
// O(n)
Original file line number Diff line number Diff line change 1
1
class Solution {
2
2
sortColors (List <int > nums) {
3
- List ? cnt = List .filled (3 , int , growable: true );
3
+ List ? cnt = List .filled (3 , 0 , growable: true );
4
4
for (int num in nums! ) {
5
5
cnt[num ]++ ;}
6
6
@@ -19,7 +19,7 @@ class Solution {
19
19
// 处理元素取值范围是 [0, R) 的计数排序
20
20
int R = 3 ;
21
21
22
- List ? cnt = List .filled (3 , int , growable: true );
22
+ List ? cnt = List .filled (3 , 0 , growable: true );
23
23
for (int num in nums! ) {
24
24
cnt[num ]++ ;
25
25
}
Original file line number Diff line number Diff line change 1
1
# AlgorithmAndDataArchitecture
2
2
3
- ## 介绍
4
3
<h2 >使用Dart语言重写数据结构与算法</h2 >
5
4
6
5
1 . 线性搜索
You can’t perform that action at this time.
0 commit comments