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 24d2e12 commit 94a7a97Copy full SHA for 94a7a97
2484-count-palindromic-subsequences.js
@@ -0,0 +1,31 @@
1
+const initialize2DArray = (n, m) => {
2
+ let d = []
3
+ for (let i = 0; i < n; i++) {
4
+ let t = Array(m).fill(0)
5
+ d.push(t)
6
+ }
7
+ return d
8
+}
9
+
10
+const mod = 1e9 + 7
11
+/**
12
+ * @param {string} s
13
+ * @return {number}
14
+ */
15
+const countPalindromes = (s) => {
16
+ let res = 0,
17
+ n = s.length,
18
+ cnt = Array(10).fill(0)
19
20
+ let tot = 0
21
+ for (let j = n - 1; j > i; j--) {
22
+ if (s[i] == s[j]) {
23
+ res += tot * (j - i - 1)
24
+ res %= mod
25
26
+ tot += cnt[s[j] - "0"]
27
28
+ cnt[s[i] - "0"]++
29
30
+ return res
31
0 commit comments