Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ddca8bf

Browse files
authoredSep 24, 2024··
Update README.md
1 parent f4ccf40 commit ddca8bf

File tree

1 file changed

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

1 file changed

+24
-0
lines changed
 

‎solution/2700-2799/2707.Extra Characters in a String/README.md

+24
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,30 @@ impl Solution {
210210
}
211211
```
212212

213+
#### JavaScript
214+
215+
```js
216+
/**
217+
* @param {string} s
218+
* @param {string[]} dictionary
219+
* @return {number}
220+
*/
221+
var minExtraChar = function (s, dictionary) {
222+
const ss = new Set(dictionary);
223+
const n = s.length;
224+
const f = Array(n + 1).fill(0);
225+
for (let i = 1; i <= n; ++i) {
226+
f[i] = f[i - 1] + 1;
227+
for (let j = 0; j < i; ++j) {
228+
if (ss.has(s.slice(j, i))) {
229+
f[i] = Math.min(f[i], f[j]);
230+
}
231+
}
232+
}
233+
return f[n];
234+
};
235+
```
236+
213237
<!-- tabs:end -->
214238

215239
<!-- solution:end -->

0 commit comments

Comments
 (0)
Please sign in to comment.