Skip to content

Commit 4225cb8

Browse files
committed
palindromic-substrings solved
1 parent bf9648a commit 4225cb8

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

palindromic-substrings/hsskey.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @param {string} s
3+
* @return {number}
4+
*/
5+
var countSubstrings = function(s) {
6+
let res = 0;
7+
8+
const countPali = (s, l, r) => {
9+
let count = 0;
10+
while (l >= 0 && r < s.length && s[l] === s[r]) {
11+
count++;
12+
l--;
13+
r++;
14+
}
15+
return count;
16+
};
17+
18+
for (let i = 0; i < s.length; i++) {
19+
res += countPali(s, i, i);
20+
res += countPali(s, i, i + 1);
21+
}
22+
23+
return res;
24+
};

0 commit comments

Comments
 (0)