Skip to content

Commit 5bd7b75

Browse files
whewchewsDaleSeo
andauthored
Fix: reverse loop direction to check palindrome
Co-authored-by: Dale Seo <[email protected]>
1 parent 34a18cd commit 5bd7b75

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

palindromic-substrings/whewchews.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ function countSubstrings(s: string): number {
44
const n = s.length;
55

66
// TC: O(N^2)
7-
for (let start = 0; start < n; start++) {
8-
for (let end = start; end >= 0; end--) {
7+
for (let start = n; start >= 0; start--) {
8+
for (let end = start; end < n; end++) {
99
if (start === end) {
1010
dict.set(`${start}:${end}`, true);
1111
} else if (start + 1 === end) {

0 commit comments

Comments
 (0)