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 029599b commit ece065aCopy full SHA for ece065a
palindromic-substrings/gitsunmin.ts
@@ -0,0 +1,21 @@
1
+/**
2
+ * https://leetcode.com/problems/palindromic-substrings/
3
+ * time complexity : O(n^2)
4
+ * space complexity : O(n)
5
+ */
6
+
7
+const expandAroundCenter = (s: string, left: number, right: number): number => {
8
+ if (left < 0 || right >= s.length || s[left] !== s[right]) {
9
+ return 0;
10
+ }
11
+ return 1 + expandAroundCenter(s, left - 1, right + 1);
12
+};
13
14
+function countSubstrings(s: string): number {
15
16
+ return [...Array(s.length).keys()].reduce((totalCount, i) => {
17
+ return totalCount +
18
+ expandAroundCenter(s, i, i) +
19
+ expandAroundCenter(s, i, i + 1);
20
+ }, 0);
21
0 commit comments