Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add js solution to lc problem: No.2707 #3554

Merged
merged 6 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions solution/2700-2799/2707.Extra Characters in a String/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,30 @@ impl Solution {
}
```

#### JavaScript

```js
/**
* @param {string} s
* @param {string[]} dictionary
* @return {number}
*/
var minExtraChar = function (s, dictionary) {
const ss = new Set(dictionary);
const n = s.length;
const f = 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.slice(j, i))) {
f[i] = Math.min(f[i], f[j]);
}
}
}
return f[n];
};
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
24 changes: 24 additions & 0 deletions solution/2700-2799/2707.Extra Characters in a String/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,30 @@ impl Solution {
}
```

#### JavaScript

```js
/**
* @param {string} s
* @param {string[]} dictionary
* @return {number}
*/
var minExtraChar = function (s, dictionary) {
const ss = new Set(dictionary);
const n = s.length;
const f = 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.slice(j, i))) {
f[i] = Math.min(f[i], f[j]);
}
}
}
return f[n];
};
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
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 = 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.slice(j, i))) {
f[i] = Math.min(f[i], f[j]);
}
}
}
return f[n];
};
Loading