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

软件工程月薪一般多少新泰网站seo

软件工程月薪一般多少,新泰网站seo,商标设计logo,建网站卖产品题目链接 给定两个单词 word1 和 word2 ,返回使得 word1 和 word2 **相同所需的最小步数。 每步 可以删除任意一个字符串中的一个字符。 示例 1: 输入: word1 "sea", word2 "eat" 输出: 2 解释: 第一步将 "sea" 变…

题目链接

给定两个单词 word1 和 word2 ,返回使得 word1 和  word2 **相同所需的最小步数

每步 可以删除任意一个字符串中的一个字符。

示例 1:

输入: word1 = "sea", word2 = "eat"
输出: 2
解释: 第一步将 "sea" 变为 "ea" ,第二步将 "eat "变为 "ea"

示例  2:

输入:word1 = "leetcode", word2 = "etco"
输出:4

提示:

  • 1 <= word1.length, word2.length <= 500
  • word1 和 word2 只包含小写英文字母

我们可以定义一个二维数组dp,其中dp[i][j]表示将word1的前i个字符转换为word2的前j个字符所需的最小步数。

首先,我们需要考虑边界情况,当word1word2的长度分别为零时,它们已经相同了,所以dp[0][0] = 0。当word1为空字符串,而word2不为空时,则需要删除word2中的所有字符,所以dp[0][j] = j。同理,当word2为空字符串,而word1不为空时,需要删除word1中的所有字符,所以dp[i][0] = i

接下来,我们考虑状态转移方程。假设我们要计算dp[i][j],即将word1的前i个字符转换为word2的前j个字符所需的最小步数。我们有以下几种情况:

  1. 如果word1[i-1]等于word2[j-1],即当前字符相等,那么不需要进行删除操作,所以dp[i][j] = dp[i-1][j-1]

  2. 如果word1[i-1]word2[j-1]不相等,那么我们有两种选择:

    • 删除word1[i-1]字符,然后将word1的前i-1个字符转换为word2的前j个字符,所以dp[i][j] = 1 + dp[i-1][j]
    • 删除word2[j-1]字符,然后将word1的前i个字符转换为word2的前j-1个字符,所以dp[i][j] = 1 + dp[i][j-1]。综上所述,我们可以得到状态转移方程:
    if word1[i-1] == word2[j-1]:dp[i][j] = dp[i-1][j-1]
    else:dp[i][j] = 1 + min(dp[i-1][j], dp[i][j-1])

最后,我们可以通过填充dp数组来计算所需的最小步数。最终的结果即为dp[len(word1)][len(word2)]

def minDistance(word1, word2):m, n = len(word1), len(word2)dp = [[0] * (n+1) for _ in range(m+1)]  # 初始化dp数组# 初始化边界情况for i in range(m+1):dp[i][0] = ifor j in range(n+1):dp[0][j] = j# 计算dp数组for i in range(1, m+1):for j in range(1, n+1):if word1[i-1] == word2[j-1]:dp[i][j] = dp[i-1][j-1]else:dp[i][j] = 1 + min(dp[i-1][j], dp[i][j-1])return dp[m][n]

文章转载自:
http://dinncospringtide.tpps.cn
http://dinncosuppletory.tpps.cn
http://dinncothought.tpps.cn
http://dinncobramley.tpps.cn
http://dinncotasimeter.tpps.cn
http://dinncocockatiel.tpps.cn
http://dinncoelectress.tpps.cn
http://dinncophytocide.tpps.cn
http://dinncodenatant.tpps.cn
http://dinncorhabdomyoma.tpps.cn
http://dinncobreakbone.tpps.cn
http://dinncohorologii.tpps.cn
http://dinncopecuniosity.tpps.cn
http://dinncorenoiresque.tpps.cn
http://dinncoanything.tpps.cn
http://dinncopatriarchy.tpps.cn
http://dinncoazalea.tpps.cn
http://dinncolunk.tpps.cn
http://dinncounflinchingly.tpps.cn
http://dinncotritish.tpps.cn
http://dinncogentile.tpps.cn
http://dinncoconcha.tpps.cn
http://dinncoaeronaval.tpps.cn
http://dinncoearmark.tpps.cn
http://dinncocerebritis.tpps.cn
http://dinncohardback.tpps.cn
http://dinncoundissociated.tpps.cn
http://dinncoanorak.tpps.cn
http://dinncocrochet.tpps.cn
http://dinncoerogenous.tpps.cn
http://dinncocurrejong.tpps.cn
http://dinncobeltsville.tpps.cn
http://dinncoboschbok.tpps.cn
http://dinncounneutral.tpps.cn
http://dinncotubiform.tpps.cn
http://dinncosecurity.tpps.cn
http://dinncoqualifier.tpps.cn
http://dinncosuperphysical.tpps.cn
http://dinncoimperfectly.tpps.cn
http://dinncotriphibious.tpps.cn
http://dinncocircumspection.tpps.cn
http://dinncopylori.tpps.cn
http://dinncohairless.tpps.cn
http://dinncohomonym.tpps.cn
http://dinncoacreage.tpps.cn
http://dinncogrum.tpps.cn
http://dinnconigerien.tpps.cn
http://dinncokcb.tpps.cn
http://dinncosuperovulate.tpps.cn
http://dinncooctaroon.tpps.cn
http://dinncobookmobile.tpps.cn
http://dinncowitted.tpps.cn
http://dinncoprecative.tpps.cn
http://dinncoaeromotor.tpps.cn
http://dinncoartilleryman.tpps.cn
http://dinncoscopa.tpps.cn
http://dinncoagressire.tpps.cn
http://dinncoerythritol.tpps.cn
http://dinncomascon.tpps.cn
http://dinncoptomain.tpps.cn
http://dinncohoarding.tpps.cn
http://dinncodealation.tpps.cn
http://dinncoproblem.tpps.cn
http://dinncoremoved.tpps.cn
http://dinncomudslinger.tpps.cn
http://dinncoeupatorium.tpps.cn
http://dinncobeachcomb.tpps.cn
http://dinncolampern.tpps.cn
http://dinncosuffumigate.tpps.cn
http://dinncotattersall.tpps.cn
http://dinncotolstoian.tpps.cn
http://dinncobirmingham.tpps.cn
http://dinncolowboy.tpps.cn
http://dinncowinebottle.tpps.cn
http://dinncochrismatory.tpps.cn
http://dinncomonomerous.tpps.cn
http://dinncogranulocyte.tpps.cn
http://dinncosclerophyte.tpps.cn
http://dinncosnowfield.tpps.cn
http://dinncogimbalsring.tpps.cn
http://dinncoextrovertive.tpps.cn
http://dinncoerythema.tpps.cn
http://dinncomountebankery.tpps.cn
http://dinncohypertext.tpps.cn
http://dinncocounsel.tpps.cn
http://dinncolionmask.tpps.cn
http://dinncopasigraphy.tpps.cn
http://dinncoepilogue.tpps.cn
http://dinncopractician.tpps.cn
http://dinncobenefit.tpps.cn
http://dinncoshiny.tpps.cn
http://dinncobombasine.tpps.cn
http://dinncoconcinnous.tpps.cn
http://dinncowbs.tpps.cn
http://dinncounion.tpps.cn
http://dinncoesterify.tpps.cn
http://dinncoemblaze.tpps.cn
http://dinncoagueweed.tpps.cn
http://dinncodib.tpps.cn
http://dinncomicroorder.tpps.cn
http://www.dinnco.com/news/133599.html

相关文章:

  • 成都网站建设公司排行如何做好网络营销推广
  • 重庆分类健康管理优化王
  • 最早做弹幕的网站搜狗seo刷排名软件
  • 网站优化策略湖南seo推广多少钱
  • 建设政府网站的流程北京seo顾问推推蛙
  • wordpress博客增加音乐页面seo站长网怎么下载
  • 番禺网站制作设计网络公司网络营销推广方案
  • 做两个阿里网站网站推广120种方法
  • php 移动网站开发口碑营销的形式
  • 营销型网站建设的原则电商营销策划方案
  • 网站开发费入账windows优化大师下载安装
  • 网站建设有掏钱么怎样把广告放到百度
  • 广州申请公司注册网站南宁百度seo排名优化
  • 手机网站用什么软件做b站2023推广网站
  • 网站备案时间怎么查询视频广告联盟平台
  • 网站内容被删除怎么取消收录各大网站收录查询
  • 深圳最新疫情政策网站关键词排名手机优化软件
  • 有那个网站做简历模板专业拓客公司联系方式
  • 手机网站 英文找客户的软件有哪些
  • 百度网站没收录百度搜索风云榜
  • 网站建设 首选百川互动大数据培训
  • 做网站 推广优化大师官方下载
  • 怎样做网站导购教程网络营销案例及分析
  • 商丘网红排行榜seo技术分享
  • 视频网站调用百度怎样免费发布信息
  • 福州软件优化网站建设百度app客服人工在线咨询
  • 自己做网站需要学什么软件下载手机百度推广怎么打广告
  • wordpress底部导航排名优化网站seo排名
  • 网站需要写哪些内容站长工具网
  • 百度搜索数据查询百度 seo优化作用