Solución
solution.tsTypeScript
function editDistance(source: string, target: string): number {
// Escribe tu solución aquí
const a = source.length;
const b = target.length;
const dp: number[][] = Array.from({length: a + 1}, () =>
new Array(b + 1).fill(0));
for(let i = 0; i <= a; i++) dp[i][0] = i;
for(let j = 0; j <= b; j++) dp[0][j] = j;
for (let i = 1; i <= a; i++){
for (let j = 1; j <= b; j++){
if(source[i -1] === target[j - 1]){
dp[i][j] = dp[i - 1][j - 1];
}else{
dp[i][j] = 1 + Math.min(
dp[i - 1][j],
dp[i][j - 1],
dp[i - 1][j - 1]
);
}
}
}
return dp[a][b];
}
// No modificar: necesario para evaluar el resultado.
export { editDistance };0respuestas