File tree Expand file tree Collapse file tree 3 files changed +67
-0
lines changed Expand file tree Collapse file tree 3 files changed +67
-0
lines changed Original file line number Diff line number Diff line change @@ -210,6 +210,30 @@ impl Solution {
210
210
}
211
211
```
212
212
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
+
213
237
<!-- tabs: end -->
214
238
215
239
<!-- solution: end -->
Original file line number Diff line number Diff line change @@ -211,6 +211,30 @@ impl Solution {
211
211
}
212
212
```
213
213
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
+
214
238
<!-- tabs: end -->
215
239
216
240
<!-- solution: end -->
Original file line number Diff line number Diff line change
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 = 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 . slice ( j , i ) ) ) {
14
+ f [ i ] = Math . min ( f [ i ] , f [ j ] ) ;
15
+ }
16
+ }
17
+ }
18
+ return f [ n ] ;
19
+ } ;
You can’t perform that action at this time.
0 commit comments