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 097eb44 commit 84e8605Copy full SHA for 84e8605
1 file changed
βpalindromic-substrings/Blossssom.tsβ
@@ -0,0 +1,25 @@
1
+/**
2
+ * @param s - λ¬Έμμ΄
3
+ * @returns - νλ¬Έ (λ€μ§μ΄ μ½μ΄λ κ°μ λ¬Έμμ΄) μ κ°―μ λ°ν
4
+ * @description
5
+ * - κ°μ κΈμμ¬λ κ°κ°μ λ°λ‘ νλ¨νλ©° ν κΈμλ νλ¬ΈμΌλ‘ νλ¨
6
+ */
7
+
8
+function countSubstrings(s: string): number {
9
+ let n = s.length;
10
+ let cnt = 0;
11
+ const dp: boolean[][] = Array.from({ length: n }, () => Array(n).fill(false));
12
13
+ for (let j = 0; j < s.length; j++) {
14
+ for (let i = 0; i <= j; i++) {
15
+ if (s[i] === s[j] && (j - i <= 2 || dp[i + 1][j - 1])) {
16
+ dp[i][j] = true;
17
+ cnt++;
18
+ }
19
20
21
+ return cnt;
22
+}
23
24
+const s = "aaa";
25
+countSubstrings(s);
0 commit comments