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 c77eba3 commit 1f3ede9Copy full SHA for 1f3ede9
115-distinct-subsequences.js
@@ -0,0 +1,25 @@
1
+/**
2
+ * @param {string} s
3
+ * @param {string} t
4
+ * @return {number}
5
+ */
6
+const numDistinct = function(s, t) {
7
+ const tlen = t.length
8
+ const slen = s.length
9
+ const mem = Array.from({ length: tlen + 1 }, () =>
10
+ new Array(slen + 1).fill(0)
11
+ )
12
+ for (let j = 0; j <= slen; j++) {
13
+ mem[0][j] = 1
14
+ }
15
+ for (let i = 0; i < tlen; i++) {
16
+ for (let j = 0; j < slen; j++) {
17
+ if (t.charAt(i) === s.charAt(j)) {
18
+ mem[i + 1][j + 1] = mem[i][j] + mem[i + 1][j]
19
+ } else {
20
+ mem[i + 1][j + 1] = mem[i + 1][j]
21
22
23
24
+ return mem[tlen][slen]
25
+}
0 commit comments