File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ //Issue 4974
2+ void main (List <String > args){
3+ const String error_message = "Usage: please provide a string" ;
4+ if (args.isEmpty || args[0 ].isEmpty){
5+ print (error_message);
6+ return ;
7+ } // end of empty check
8+
9+ Map <String , int > frequency = {};
10+ bool duplicate_not_found = true ;
11+
12+ for (int i = 0 ; i < args[0 ].length; i ++ ){
13+ String char = args[0 ][i];
14+ if (RegExp (r'[a-zA-Z0-9]' ).hasMatch (char)) {
15+ frequency[char] = (frequency[char] ?? 0 ) + 1 ;
16+ }
17+ } // end of checking duplicate characters
18+
19+ //either print all duplicate letters or set flag duplicate letters not found
20+ frequency.forEach ((char, count){
21+ if (count > 1 ) {
22+ duplicate_not_found = false ; // at least 1 duplicate letter is found
23+ print ('$char : $count ' );
24+ }
25+ });
26+ // print if no duplicate characters
27+ if (duplicate_not_found == true ){
28+ print ("No duplicate characters" );
29+ }
30+ }
You can’t perform that action at this time.
0 commit comments