[Leetcode] Edit Distance
来源:互联网 发布:淘宝的优惠券是真的吗 编辑:程序博客网 时间:2024/06/05 20:13
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)
You have the following 3 operations permitted on a word:
a) Insert a character
b) Delete a character
c) Replace a character
public class Solution { private int min(int a, int b, int c) { int min = a < b? a : b; min = min < c? min : c; return min; } public int minDistance(String word1, String word2) { int m = word1.length(); int n = word2.length(); int[][] result = new int[m + 1][n + 1]; for(int i = 0; i <= m; i++) { for (int j = 0; j <= n; j++) { if(i == 0) { result[0][j] = j; } else if(j == 0) { result[i][0] = i; } else { if(word1.charAt(i-1) == word2.charAt(j-1)) { result[i][j] = result[i - 1][ j - 1]; } else { result[i][j] = 1 + min(result[i - 1][j - 1], result[i][j-1], result[i-1][j]); } } } } return result[m][n]; }}
0 0
- LeetCode: Edit Distance
- LeetCode Edit Distance
- LeetCode: Edit Distance
- [Leetcode] Edit Distance
- leetcode 19: Edit Distance
- [LeetCode] Edit Distance
- [Leetcode] Edit Distance
- LeetCode Edit Distance
- [LeetCode] Edit Distance
- [LeetCode]Edit Distance
- Leetcode: Edit Distance
- [leetcode]Edit Distance
- LeetCode-Edit Distance
- [leetcode] Edit Distance
- LeetCode - Edit Distance
- leetcode之Edit Distance
- leetcode edit distance
- 【leetcode】Edit Distance
- Xcode升级到8以后某些插件不能用的问题
- Android 各个版本WebView
- Python之二:几个数字库
- 四元数,欧拉角和旋转矩阵之间的互相转换
- js 页面埋点
- [Leetcode] Edit Distance
- HTTP 协议详解
- 多线程-关键字Volatile
- Intent跳转页面的几种方式
- 总结一下今天在编程中遇到的问题和相应的解决办法
- Servlet
- 还是杂
- earlysuspend调用过程
- QT学习--connect使用详解