File tree Expand file tree Collapse file tree 3 files changed +32
-1
lines changed
lib/src/medium/647.palindromic_substrings Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -17,14 +17,17 @@ class Solution {
1717 int countPalindromes (String s, int left, int right) {
1818 int count = 0 ;
1919 while (left >= 0 && right < s.length && s[left] == s[right]) {
20+ // print(s.substring(left, right + 1));
21+
2022 count++ ;
2123 left-- ;
2224 right++ ;
2325 }
26+
2427 return count;
2528 }
2629}
2730
2831void main (List <String > args) {
29- print (Solution ().countSubstrings ('aaa ' ));
32+ print (Solution ().countSubstrings ('racecar ' ));
3033}
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ import 'medium/3.longest_substring_without_repeating_characters.test.dart'
2929import 'medium/424.longest_repeating_character_replacement.test.dart' as longest_repeating_character_replacement;
3030import 'medium/49.group_anagrams.test.dart' as group_anagrams;
3131import 'medium/5.longest_palindromic_substring.test.dart' as longest_palindromic_substring;
32+ import 'medium/647.palindromic_substrings.test.dart' as palindromic_substrings;
3233import 'medium/912.sort_an_array.test.dart' as sort_an_array;
3334
3435void main () {
@@ -60,5 +61,6 @@ void main() {
6061 valid_anagram.main ();
6162 group_anagrams.main ();
6263 longest_palindromic_substring.main ();
64+ palindromic_substrings.main ();
6365 });
6466}
Original file line number Diff line number Diff line change 1+ import 'package:leetcode/src/medium/647.palindromic_substrings/main.dart' ;
2+ import 'package:test/test.dart' ;
3+
4+ void main () {
5+ group ('sort_an_array' , () {
6+ final f = Solution ().countSubstrings;
7+
8+ test ('returns 0 for empty input' , () {
9+ expect (f ('' ), equals (0 ));
10+ });
11+
12+ test ('returns correct count for single-character input' , () {
13+ expect (f ('a' ), equals (1 ));
14+ });
15+
16+ test ('returns correct count for input with single-character palindromic substrings' , () {
17+ expect (f ('abc' ), equals (3 ));
18+ });
19+
20+ test ('returns correct count for input with palindromes' , () {
21+ expect (f ('aba' ), equals (4 ));
22+ expect (f ('abba' ), equals (6 ));
23+ expect (f ('racecar' ), equals (10 ));
24+ });
25+ }); // group 'sort_an_array'
26+ }
You can’t perform that action at this time.
0 commit comments