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() {
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)
Original file line number Diff line number Diff line change 11class 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 }
Original file line number Diff line number Diff line change 11# AlgorithmAndDataArchitecture
22
3- ## 介绍
43<h2 >使用Dart语言重写数据结构与算法</h2 >
54
651 . 线性搜索
You can’t perform that action at this time.
0 commit comments