首页 > 其他分享 >[LeetCode][72]edit-distance

[LeetCode][72]edit-distance

时间:2023-08-23 09:03:48浏览次数:33  
标签:operations distance edit character remove replace word1 word2 LeetCode

Content

Given two strings word1 and word2, return the minimum number of operations required to convert word1 to word2.

You have the following three operations permitted on a word:

  • Insert a character
  • Delete a character
  • Replace a character

 

Example 1:

Input: word1 = "horse", word2 = "ros"
Output: 3
Explanation:
horse -> rorse (replace 'h' with 'r')
rorse -> rose (remove 'r')
rose -> ros (remove 'e')

Example 2:

Input: word1 = "intention", word2 = "execution"
Output: 5
Explanation:
intention -> inention (remove 't')
inention -> enention (replace 'i' with 'e')
enention -> exention (replace 'n' with 'x')
exention -> exection (replace 'n' with 'c')
exection -> execution (insert 'u')

 

Constraints:

  • 0 <= word1.length, word2.length <= 500
  • word1 and word2 consist of lowercase English letters.
Related Topics
  • 字符串
  • 动态规划

  • 标签:operations,distance,edit,character,remove,replace,word1,word2,LeetCode
    From: https://www.cnblogs.com/shea24/p/17650093.html
  • 相关文章

    • Leetcode 349.两个数组的交集(Intersection of two arrays)
      题目链接......
    • Leetcode 849. 到最近的人的最大距离
      题目描述给你一个数组seats表示一排座位,其中seats[i]=1代表有人坐在第i个座位上,seats[i]=0代表座位i上是空的(下标从0开始)。至少有一个空座位,且至少有一人已经坐在座位上。亚历克斯希望坐在一个能够使他与离他最近的人之间的距离达到最大化的座位上。返回他到离......
    • LeetCode.钥匙和房间
      1.代码:有 n 个房间,房间按从 0 到 n-1 编号。最初,除 0 号房间外的其余所有房间都被锁住。你的目标是进入所有的房间。然而,你不能在没有获得钥匙的时候进入锁住的房间。当你进入一个房间,你可能会在里面找到一套不同的钥匙,每把钥匙上都有对应的房间号,即表示钥匙可以打开的房......
    • Leetcode 两个队列实现栈 swift
      queue1 是最后生成的栈queue2是临时队列,把新进来的先放进去,再把queue1里的数据从头到尾读进去,然后互换classMyStack{varqueue1:[Int]=[]varqueue2:[Int]=[]init(){}funcpush(_x:Int){queue2.append(x)whil......
    • json-schema编辑器(json-schema-editor)
       最近在找一个 json-schema的编辑器,在网上找了找,以下两个项目用的比较多一、两款json-schema-editor1、vue-json-schema-editor-visual一个高效易用的基于Vue+ElementUI的json-schema编辑器。git地址:https://github.com/giscafer/vue-json-schema-editor-visualdem......
    • LeetCode338.比特位计数
      先以2,3为例,它们的二进制分别是10、11,可以看到,忽略其二进制中最高位的1之后,这组数中二进制位为1的数量分别和数字0,1中二进制位为1的数量相同,再以4,5,6,7为例,他们的二进制分别是100、101、110、111,忽略其二进制中最高位的1之后,这组数中二进制位为1的数量分别和数字0,1,2,3中二进制位为1的......
    • 如何复制word的图文到xhEditor中自动上传
      ​ 1.编辑器修改(可选)1.1在 ueditor/config.json 中添加代码块    /* 上传word配置 */    "wordActionName":"wordupload",/* 执行上传视频的action名称 */    "wordFieldName":"upfile",/* 提交的视频表单名称 */    "wordPathFormat":"/p......
    • 如何复制word的图文到wangEditor中自动上传
      ​ 这种方法是servlet,编写好在web.xml里配置servlet-class和servlet-mapping即可使用后台(服务端)java服务代码:(上传至ROOT/lqxcPics文件夹下)<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%@     page contentType="text/html;cha......
    • LeetCode-164. 最大间距(Java)
      一、前言......
    • Leetcode 59. 螺旋矩阵 II && 剑指 Offer 29. 顺时针打印矩阵
      这两个题非常相似,但是前者较为简单,后者较难。由于前者访问的矩阵是方阵,因此可以通过迭代去做(因为方阵每次迭代,长和宽缩水的大小是一样的,但是矩阵不可以,因为矩阵最后一次迭代,长和宽的缩水不一定一样)classSolution{public:vector<vector<int>>generateMatrix(intn){......