Edit Distance
来源:互联网 发布:金融行业数据分析 编辑:程序博客网 时间:2024/06/05 12:27
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
class Solution: # @return an integer def minDistance(self, word1, word2): mark = [[0 for j in range(len(word2)+1)] for i in range(len(word1)+1)] for i in range(len(word1)+1): for j in range(len(word2)+1): if i==0 or j==0: if i==0: mark[i][j]=j else: mark[i][j]=i else: if word1[i-1]==word2[j-1]: mark[i][j]=mark[i-1][j-1] else: mark[i][j]=min(mark[i-1][j-1]+1,mark[i][j-1]+1,mark[i-1][j]+1) return mark[-1][-1]
0 0
- edit distance
- Edit Distance
- edit distance
- Edit Distance
- Edit Distance
- Edit Distance
- Edit Distance
- Edit Distance
- Edit Distance
- Edit Distance
- Edit Distance
- Edit Distance
- Edit Distance
- Edit Distance
- Edit Distance
- Edit Distance
- Edit Distance
- Edit Distance
- 使用InetAddress
- Windows内存管理
- SVN服务器搭建和使用(1)
- Visual C++ 中操纵 MS Word 123
- Delphi开发标记为安全的ActiveX控件
- Edit Distance
- Eclipse搭建SSH(Struts2+Spring3+Hibernate3)框架项目教程 (copy)
- unity之Animation组件
- Vision引擎中着色器效果新建和编辑功能介绍
- 让DIV的滚动条自动滚动到最底部 - 4种方法
- 数据库:mongodb与关系型数据库相比的优缺点zz
- SVN服务器搭建和使用(2)
- Microsoft Office Development with Visual Studio
- 构建maven企业级应用 SSI框架