[leetcode]Edit Distance @ Python - 南郭子綦 - 博客园: "class Solution:
# @return an integer
def minDistance(self, word1, word2):
m=len(word1)+1; n=len(word2)+1
dp = [[0 for i in range(n)] for j in range(m)]
for i in range(n):
dp[0][i]=i
for i in range(m):
dp[i][0]=i
for i in range(1,m):
for j in range(1,n):
dp[i][j]=min(dp[i-1][j]+1, dp[i][j-1]+1, dp[i-1][j-1]+(0 if word1[i-1]==word2[j-1] else 1))
return dp[m-1][n-1]"
'via Blog this'
Blog Archive
-
▼
2014
(190)
-
▼
August
(23)
- 十道海量数据处理面试题与十个方法大总结 - 结构之法 算法之道 - 博客频道 - CSDN.NET
- Backtracking | Set 2 (Rat in a Maze) - GeeksforGeeks
- Amazon Jobs | Push the Envelope with Amazon’s Spee...
- [leetcode]Longest Consecutive Sequence @ Python - ...
- AIDasr - 博客园
- Find all combinations of coins when given some dol...
- [leetcode]Edit Distance @ Python - 南郭子綦 - 博客园
- Google APAC 2015 University Graduates Test
- My Own Notes: LeetCode (Python): Flatten Binary Tr...
- LeetCode题解整理版(二) | Coding 4 Fun
- Binary Tree Preorder Inorder Postorder Traversal ...
- Binary Tree Level Order Traversal II | LeetCode OJ
- LeetCode — Binary Tree Preorder Traversal(C++ Java...
- 前女友因为我没进Google而和我分手 (转载) - 未名空间(mitbbs.com)
- [Mitbbs]FB的intern和准备的经历 - - 博客频道 - CSDN.NET
- Google coding Style Guide
- LeetCode OJ --问题与解答 前言
- Lexi's Leetcode solutions
- LeetCode 分类
- Can Mobile Technologies and Big Data Improve Healt...
- 喀什葛尔胡杨歌词
- Study: Noise-Induced Hearing Loss Alters Brain Res...
- How to Focus
-
▼
August
(23)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment