Skip to content

Commit f19566a

Browse files
committed
refacotr: add more detail description
1 parent 29ec5eb commit f19566a

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

palindromic-substrings/tolluset.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ function countSubstrings(s: string): number {
1111
result = 0;
1212

1313
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
1515
if (i < right) {
1616
pit[i] = Math.min(right - i, pit[center * 2 - i]);
1717
}
1818

19-
// Expand around i
19+
// Expand around i until it's not a palindrome and not over left or right
2020
while (
2121
i + pit[i] + 1 < len &&
2222
i - pit[i] - 1 >= 0 &&
@@ -25,13 +25,13 @@ function countSubstrings(s: string): number {
2525
pit[i]++;
2626
}
2727

28-
// Update center and right
28+
// If pit value is the new rightmost center, update center and right
2929
if (i + pit[i] > right) {
3030
center = i;
3131
right = i + pit[i];
3232
}
3333

34-
// Add to result
34+
// Add the number of palindromes with center i to the result
3535
result += Math.floor((pit[i] + 1) / 2);
3636
}
3737

0 commit comments

Comments
 (0)