Movatterモバイル変換


[0]ホーム

URL:


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

Commit5147710

Browse files
Merge pull requestyoungyangyang04#497 from jackeyjia/patch-17
add js solution for minDistance
2 parents40cd0c2 +49d68b0 commit5147710

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

‎problems/0072.编辑距离.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,32 @@ func Min(args ...int) int {
307307
```
308308

309309

310+
Javascript:
311+
```javascript
312+
constminDistance= (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+
```
310336

311337
-----------------------
312338
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp