Skip to content

Commit 5165eb4

Browse files
committed
solve: palindromic substrings
1 parent 48e6101 commit 5165eb4

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

palindromic-substrings/wogha95.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// TC: O(n^3)
2+
// SC: O(1)
3+
4+
/**
5+
* @param {string} s
6+
* @return {number}
7+
*/
8+
var countSubstrings = function(s) {
9+
let count = 0;
10+
11+
for (let left = 0; left < s.length; left++) {
12+
for (let right = left; right < s.length; right++) {
13+
if(checkIsPalinDrome(left, right)) {
14+
count += 1;
15+
}
16+
}
17+
}
18+
19+
return count;
20+
21+
function checkIsPalinDrome(left, right) {
22+
while (left < right) {
23+
if (s[left] !== s[right]) {
24+
return false;
25+
}
26+
left += 1;
27+
right -= 1;
28+
}
29+
30+
return true;
31+
}
32+
};

0 commit comments

Comments
 (0)