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 761a237 commit 9e34767Copy full SHA for 9e34767
palindromic-substrings/byol-han.js
@@ -0,0 +1,24 @@
1
+/**
2
+ * https://leetcode.com/problems/palindromic-substrings/submissions/1644425061/
3
+ * @param {string} s
4
+ * @return {number}
5
+ */
6
+var countSubstrings = function (s) {
7
+ let count = 0;
8
+
9
+ // Helper function to expand around the center
10
+ function expandAroundCenter(left, right) {
11
+ while (left >= 0 && right < s.length && s[left] === s[right]) {
12
+ count++; // Found a palindrome
13
+ left--;
14
+ right++;
15
+ }
16
17
18
+ for (let i = 0; i < s.length; i++) {
19
+ expandAroundCenter(i, i); // Odd-length palindromes
20
+ expandAroundCenter(i, i + 1); // Even-length palindromes
21
22
23
+ return count;
24
+};
0 commit comments