Skip to content

Commit

Permalink
Create Solution.js
Browse files Browse the repository at this point in the history
  • Loading branch information
07subhadip committed Sep 23, 2024
1 parent 98abde6 commit 95eacb4
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions solution/2700-2799/2707.Extra Characters in a String/Solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @param {string} s
* @param {string[]} dictionary
* @return {number}
*/
var minExtraChar = function(s, dictionary) {
const ss = new Set(dictionary);
const n = s.length;
const f = new Array(n + 1).fill(0);
for (let i = 1; i <= n; ++i) {
f[i] = f[i - 1] + 1;
for (let j = 0; j < i; ++j) {
if (ss.has(s.substring(j, i))) {
f[i] = Math.min(f[i], f[j]);
}
}
}
return f[n];
};

0 comments on commit 95eacb4

Please sign in to comment.