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 341a991 commit ffa0e87Copy full SHA for ffa0e87
palindromic-substrings/moonjonghoo.js
@@ -0,0 +1,22 @@
1
+/**
2
+ * @param {string} s
3
+ * @return {number}
4
+ */
5
+var countSubstrings = function (s) {
6
+ let count = 0;
7
+
8
+ const expand = (left, right) => {
9
+ while (left >= 0 && right < s.length && s[left] === s[right]) {
10
+ count++;
11
+ left--;
12
+ right++;
13
+ }
14
+ };
15
16
+ for (let i = 0; i < s.length; i++) {
17
+ expand(i, i); // 홀수 길이 중심 (예: "aba")
18
+ expand(i, i + 1); // 짝수 길이 중심 (예: "aa")
19
20
21
+ return count;
22
+};
0 commit comments