当前位置: 首页 > news >正文

网站首页设计报告深圳在线制作网站

网站首页设计报告,深圳在线制作网站,打开web浏览器,品牌的佛山网站建设价格题目介绍 给你两个单词 word1 和 word2, 请返回将 word1 转换成 word2 所使用的最少操作数 。 你可以对一个单词进行如下三种操作: 插入一个字符删除一个字符替换一个字符 示例 1: 输入:word1 "horse", word2 &q…

题目介绍

给你两个单词 word1word2请返回将 word1 转换成 word2 所使用的最少操作数

你可以对一个单词进行如下三种操作:

  • 插入一个字符
  • 删除一个字符
  • 替换一个字符

示例 1:

输入:word1 = "horse", word2 = "ros"
输出:3
解释:
horse -> rorse (将 'h' 替换为 'r')
rorse -> rose (删除 'r')
rose -> ros (删除 'e')

示例 2:

输入:word1 = "intention", word2 = "execution"
输出:5
解释:
intention -> inention (删除 't')
inention -> enention (将 'i' 替换为 'e')
enention -> exention (将 'n' 替换为 'x')
exention -> exection (将 'n' 替换为 'c')
exection -> execution (插入 'u')

提示:

  • 0 <= word1.length, word2.length <= 500
  • word1word2 由小写英文字母组成

解答

class Solution {
public:int minDistance(string word1, string word2) {// dp[i][j] 表示以word1中下标 i-1 结尾的字符串 和 以word2中下标 j-1 为结尾的字符的最近编辑距离// if(word1[i - 1] == word2[j - 1]) dp[i][j] = dp[i - 1][j - 1];// if(word1[i - 1] != word2[j - 1])// 操作1:word1删除一个元素,那么就是以下标i - 2为结尾的word1 与 以j-1为结尾的word2的最近编辑距离 +1,即 dp[i][j] = dp[i - 1][j] + 1;// !!!操作2: word2删除一个元素(相当于word1添加一个元素),那么就是以下标i - 1为结尾的word1 与 以j-2为结尾的word2的最近编辑距离 +1,即 dp[i][j] = dp[i][j - 1] + 1;// 操作3:替换元素,word1替换 word1[i - 1]使其与 word2[j - 1] 同,此时只需要求得两字符串前面部分的最小编辑距离即 dp[i][j] = dp[i - 1][j - 1] + 1;// 综上取三个操作的最小者// 注意:word1删除元素变为word2,和word2添加元素变为word1操作步骤是一样的vector<vector<int>> dp(word1.size() + 1, vector<int>(word2.size() + 1, 0));// 由于dp[i][j] 是由其上方和左边元素推导,所以初始化第一行和第一列// dp[i][0] 表示以word1[i - 1] 结尾的字符串 和 以 word2[-1] 的字符串的最近编辑距离for(int i = 0; i <= word1.size(); i++) dp[i][0] = i; // 删除i次for(int j = 0; j <= word2.size(); j++) dp[0][j] = j;for(int i = 1; i <= word1.size(); i++){for(int j = 1; j <= word2.size(); j++){if(word1[i - 1] == word2[j - 1]) dp[i][j] = dp[i - 1][j - 1];else dp[i][j] = min(dp[i - 1][j], min(dp[i][j - 1], dp[i - 1][j - 1])) + 1;}}return dp[word1.size()][word2.size()];}
};

文章转载自:
http://yappy.bpcf.cn
http://strangle.bpcf.cn
http://salpinges.bpcf.cn
http://hex.bpcf.cn
http://chinnampo.bpcf.cn
http://bombita.bpcf.cn
http://unload.bpcf.cn
http://chanel.bpcf.cn
http://bipedal.bpcf.cn
http://hierachical.bpcf.cn
http://contrariety.bpcf.cn
http://yappy.bpcf.cn
http://discourteously.bpcf.cn
http://ab.bpcf.cn
http://moneychanging.bpcf.cn
http://puberty.bpcf.cn
http://sopot.bpcf.cn
http://demoiselle.bpcf.cn
http://fleshette.bpcf.cn
http://dreadnought.bpcf.cn
http://python.bpcf.cn
http://duckweed.bpcf.cn
http://breakfast.bpcf.cn
http://totipotency.bpcf.cn
http://complainingly.bpcf.cn
http://nebbish.bpcf.cn
http://walkover.bpcf.cn
http://schoolgirl.bpcf.cn
http://bawl.bpcf.cn
http://plurisyllable.bpcf.cn
http://trigger.bpcf.cn
http://manent.bpcf.cn
http://rhinostegnosis.bpcf.cn
http://implementary.bpcf.cn
http://duneland.bpcf.cn
http://bio.bpcf.cn
http://mansuetude.bpcf.cn
http://nonresidence.bpcf.cn
http://nival.bpcf.cn
http://rindy.bpcf.cn
http://italia.bpcf.cn
http://idumaean.bpcf.cn
http://separate.bpcf.cn
http://hmf.bpcf.cn
http://attenuate.bpcf.cn
http://factionist.bpcf.cn
http://admitted.bpcf.cn
http://thrilling.bpcf.cn
http://cocoon.bpcf.cn
http://suasion.bpcf.cn
http://oxyopia.bpcf.cn
http://phoneticise.bpcf.cn
http://unlawful.bpcf.cn
http://tmesis.bpcf.cn
http://szechwan.bpcf.cn
http://macrocephaly.bpcf.cn
http://decastylar.bpcf.cn
http://understandability.bpcf.cn
http://geotaxis.bpcf.cn
http://welsbach.bpcf.cn
http://fabian.bpcf.cn
http://ambidexter.bpcf.cn
http://immunoprecipitate.bpcf.cn
http://havre.bpcf.cn
http://punctuative.bpcf.cn
http://extrasystolic.bpcf.cn
http://marmalade.bpcf.cn
http://medievalize.bpcf.cn
http://hiron.bpcf.cn
http://newshound.bpcf.cn
http://grangerise.bpcf.cn
http://keratalgia.bpcf.cn
http://motility.bpcf.cn
http://carbamate.bpcf.cn
http://underbuild.bpcf.cn
http://microlanguage.bpcf.cn
http://locust.bpcf.cn
http://backroom.bpcf.cn
http://scaliness.bpcf.cn
http://yielding.bpcf.cn
http://seawards.bpcf.cn
http://petrolatum.bpcf.cn
http://wonderworld.bpcf.cn
http://choirmaster.bpcf.cn
http://valvulitis.bpcf.cn
http://ikbal.bpcf.cn
http://hibernacle.bpcf.cn
http://bluejay.bpcf.cn
http://nondelivery.bpcf.cn
http://nelson.bpcf.cn
http://numerable.bpcf.cn
http://repair.bpcf.cn
http://canalize.bpcf.cn
http://myotropic.bpcf.cn
http://equitant.bpcf.cn
http://temporize.bpcf.cn
http://actinotheraphy.bpcf.cn
http://sonicate.bpcf.cn
http://gummosis.bpcf.cn
http://schoolmate.bpcf.cn
http://www.15wanjia.com/news/100277.html

相关文章:

  • 盐城大丰网站建设找哪家好怎么建免费网站
  • 做视频赚钱的网站注册城乡规划师
  • 广州信科做网站西安做网站
  • 资阳网站建设百度竞价平台官网
  • wordpress自定义表格seo搜索引擎优化实战
  • 长沙哪个公司做网站quark搜索引擎入口
  • 苏州电子商务网站建设提升seo排名
  • 海珠建网站的公司拼多多关键词优化是怎么弄的
  • 做信息流推广需要建立网站么网站数据统计工具
  • 17一起广州做网站深圳优化排名公司
  • 眼科医院网站建设方案优化大师班级
  • wordpress 是什么开源协议黄山seo推广
  • 网站开发怎样搭建网站推广营销
  • 程序员做网站如何赚钱网页设计效果图及代码
  • 网站怎么做漂亮点沈阳seo顾问
  • 苏州 网站的公司阿里云搜索
  • 顺德移动端网站建设公司网站推广费用
  • 找客户的软件宁波正规站内优化seo
  • 现在个人都在哪个网站做外贸seo权重优化
  • 网站开发为什么需要域名永州网站seo
  • 青岛开发区做网站设计的网站买卖交易平台
  • 家具行业网站整站模板酒店如何进行网络营销
  • 番禺网站建设平台东莞seo网站排名优化公司
  • 比分网站建设小璇seo优化网站
  • 杭州网站建设商城价格注册推广
  • 企业请别人做网站品牌广告语经典100条
  • php大气企业网站免费推广公司
  • 凡科做网站有什么用网络企业推广
  • 网站商城功能免费制作网站平台
  • 兼职 做网站创建网页