Skip to content

Commit e7c0e56

Browse files
committed
refactor: 647. Palindromic Substrings
1 parent 7812d91 commit e7c0e56

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

palindromic-substrings/gwbaik9717.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,28 @@ var countSubstrings = function (s) {
1010
const dp = Array.from({ length: n }, () =>
1111
Array.from({ length: n }, () => false)
1212
);
13+
let answer = 0;
1314

1415
for (let end = 0; end < n; end++) {
1516
for (let start = end; start >= 0; start--) {
1617
if (start === end) {
1718
dp[start][end] = true;
19+
answer++;
1820
continue;
1921
}
2022

2123
if (start + 1 === end) {
2224
if (s[start] === s[end]) {
2325
dp[start][end] = true;
26+
answer++;
2427
}
2528
continue;
2629
}
2730

2831
if (s[start] === s[end] && dp[start + 1][end - 1]) {
2932
dp[start][end] = true;
30-
continue;
31-
}
32-
}
33-
}
34-
35-
let answer = 0;
36-
37-
for (let i = 0; i < n; i++) {
38-
for (let j = 0; j < n; j++) {
39-
if (dp[i][j]) {
4033
answer++;
34+
continue;
4135
}
4236
}
4337
}

0 commit comments

Comments
 (0)