Skip to content

Commit 95eacb4

Browse files
authored
Create Solution.js
1 parent 98abde6 commit 95eacb4

File tree

1 file changed

+19
-0
lines changed
  • solution/2700-2799/2707.Extra Characters in a String

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)