Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 46a2880

Browse files
committed
Update README_EN.md
1 parent 7a18121 commit 46a2880

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_EN.md‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,30 @@ impl Solution {
211211
}
212212
```
213213

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

216240
<!-- solution:end -->

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /