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 @@ -149,6 +149,32 @@ class Solution:
149
149
Go:
150
150
151
151
152
+ Javascript:
153
+ ``` javascript
154
+ const minDistance = (word1 , word2 ) => {
155
+ let dp = Array .from (Array (word1 .length + 1 ), () => Array (word2 .length + 1 ).fill (0 ));
156
+
157
+ for (let i = 1 ; i <= word1 .length ; i++ ) {
158
+ dp[i][0 ] = i;
159
+ }
160
+
161
+ for (let j = 1 ; j <= word2 .length ; j++ ) {
162
+ dp[0 ][j] = j;
163
+ }
164
+
165
+ for (let i = 1 ; i <= word1 .length ; i++ ) {
166
+ for (let j = 1 ; j <= word2 .length ; j++ ) {
167
+ if (word1[i- 1 ] === word2[j- 1 ]) {
168
+ dp[i][j] = dp[i- 1 ][j- 1 ];
169
+ } else {
170
+ dp[i][j] = Math .min (dp[i- 1 ][j] + 1 , dp[i][j- 1 ] + 1 , dp[i- 1 ][j- 1 ] + 2 );
171
+ }
172
+ }
173
+ }
174
+
175
+ return dp[word1 .length ][word2 .length ];
176
+ };
177
+ ```
152
178
153
179
154
180
-----------------------
You can’t perform that action at this time.
0 commit comments