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 98abde6 commit 95eacb4Copy full SHA for 95eacb4
solution/2700-2799/2707.Extra Characters in a String/Solution.js
@@ -0,0 +1,19 @@
1
+/**
2
+ * @param {string} s
3
+ * @param {string[]} dictionary
4
+ * @return {number}
5
+ */
6
+var minExtraChar = function(s, dictionary) {
7
+ const ss = new Set(dictionary);
8
+ const n = s.length;
9
+ const f = new Array(n + 1).fill(0);
10
+ for (let i = 1; i <= n; ++i) {
11
+ f[i] = f[i - 1] + 1;
12
+ for (let j = 0; j < i; ++j) {
13
+ if (ss.has(s.substring(j, i))) {
14
+ f[i] = Math.min(f[i], f[j]);
15
+ }
16
17
18
+ return f[n];
19
+};
0 commit comments