博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[LEETCODE] 72 Edit Distance
阅读量:6989 次
发布时间:2019-06-27

本文共 896 字,大约阅读时间需要 2 分钟。

72. Edit DistanceDescriptionHintsSubmissionsDiscussSolutionDiscussPick OneGiven 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 characterb) Delete a characterc) Replace a character

这网站不错。。嗯

ED裸题

class Solution {public:    int minDistance(string word1, string word2) {       int lens=word1.size() ;    int lent=word2.size() ;    int f[1000][1000];    for(int i=1;i<=lens;i++) f[i][0]=i;    for(int i=1;i<=lent;i++) f[0][i]=i;    for(int i=1;i<=lens;i++){        for(int j=1;j<=lent;j++){            if(word1[i-1]==word2[j-1]) f[i][j]=f[i-1][j-1];            else{                f[i][j]=min(f[i-1][j-1],min(f[i][j-1],f[i-1][j]))+1;            }        }    }     return f[lens][lent];    }};

转载于:https://www.cnblogs.com/ghostcai/p/9247507.html

你可能感兴趣的文章
人工智能范畴及深度学习主流框架,谷歌 TensorFlow,IBM Watson认知计算领域IntelligentBehavior介绍...
查看>>
PCL深度图像(1)
查看>>
js-ES6学习笔记-for...of循环
查看>>
extjs_06_grid(列锁定&amp;列分组)
查看>>
elasticsearch搜索类型简单介绍
查看>>
第十章 五种对称加密算法总结
查看>>
android非法字符的判定、表情符号的判定
查看>>
为了眼睛的健康改变电脑的色调-献给长期坐在电脑前的朋友
查看>>
How to enable LDAP over SSL with a third-party certification authority
查看>>
细说 Data URI
查看>>
SqlServer 查询死锁,杀死死锁进程
查看>>
SNS商业
查看>>
利用ICSharpCode.SharpZipLib.dll实现简单加解压 转
查看>>
今天才知道什么是欲哭无泪
查看>>
pgpool 后台运行方法
查看>>
精品素材:推荐15套非常漂亮的 iOS 图标素材
查看>>
wpf之ComboBox绑定
查看>>
使用HttpSessionListener接口监听Session的创建和失效
查看>>
应用更新iOS 开发:应用内实现 更新提醒
查看>>
Android ToggleButton Example--开关按钮
查看>>