File tree Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change @@ -11,12 +11,12 @@ function countSubstrings(s: string): number {
11
11
result = 0 ;
12
12
13
13
for ( let i = 0 ; i < len ; i ++ ) {
14
- // Set pit[i]
14
+ // If i is within the rightmost center, copy the pit value from the mirror
15
15
if ( i < right ) {
16
16
pit [ i ] = Math . min ( right - i , pit [ center * 2 - i ] ) ;
17
17
}
18
18
19
- // Expand around i
19
+ // Expand around i until it's not a palindrome and not over left or right
20
20
while (
21
21
i + pit [ i ] + 1 < len &&
22
22
i - pit [ i ] - 1 >= 0 &&
@@ -25,13 +25,13 @@ function countSubstrings(s: string): number {
25
25
pit [ i ] ++ ;
26
26
}
27
27
28
- // Update center and right
28
+ // If pit value is the new rightmost center, update center and right
29
29
if ( i + pit [ i ] > right ) {
30
30
center = i ;
31
31
right = i + pit [ i ] ;
32
32
}
33
33
34
- // Add to result
34
+ // Add the number of palindromes with center i to the result
35
35
result += Math . floor ( ( pit [ i ] + 1 ) / 2 ) ;
36
36
}
37
37
You can’t perform that action at this time.
0 commit comments