File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -307,6 +307,32 @@ func Min(args ...int) int {
307
307
```
308
308
309
309
310
+ Javascript:
311
+ ``` javascript
312
+ const minDistance = (word1 , word2 ) => {
313
+ let dp = Array .from (Array (word1 .length + 1 ), () => Array (word2 .length + 1 ).fill (0 ));
314
+
315
+ for (let i = 1 ; i <= word1 .length ; i++ ) {
316
+ dp[i][0 ] = i;
317
+ }
318
+
319
+ for (let j = 1 ; j <= word2 .length ; j++ ) {
320
+ dp[0 ][j] = j;
321
+ }
322
+
323
+ for (let i = 1 ; i <= word1 .length ; i++ ) {
324
+ for (let j = 1 ; j <= word2 .length ; j++ ) {
325
+ if (word1[i- 1 ] === word2[j- 1 ]) {
326
+ dp[i][j] = dp[i- 1 ][j- 1 ];
327
+ } else {
328
+ dp[i][j] = Math .min (dp[i- 1 ][j] + 1 , dp[i][j- 1 ] + 1 , dp[i- 1 ][j- 1 ] + 1 );
329
+ }
330
+ }
331
+ }
332
+
333
+ return dp[word1 .length ][word2 .length ];
334
+ };
335
+ ```
310
336
311
337
-----------------------
312
338
* 作者微信:[ 程序员Carl] ( https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw )
You can’t perform that action at this time.
0 commit comments