We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b776697 commit 1d1cecaCopy full SHA for 1d1ceca
palindromic-substrings/hyejjun.js
@@ -0,0 +1,32 @@
1
+/**
2
+ * @param {string} s
3
+ * @return {number}
4
+ */
5
+var countSubstrings = function (s) {
6
+ let count = 0;
7
+
8
+ function checkPalindromic(left, right) {
9
+ while (left >= 0 && right < s.length && s[left] === s[right]) {
10
+ count++;
11
+ left--;
12
+ right++;
13
+ }
14
15
16
17
+ for (let i = 0; i < s.length; i++) {
18
+ checkPalindromic(i, i);
19
+ checkPalindromic(i, i + 1);
20
21
22
+ return count;
23
+};
24
25
+console.log(countSubstrings("abc"));
26
+console.log(countSubstrings("aaa"));
27
28
29
+/*
30
+Time Complexity : O(n^2)
31
+Space Complexity: O(1)
32
+*/
0 commit comments