public class Solution {
public int MinDistance(string word1, string word2) {
int[,] dp = new int[word1.Length + , word2.Length + ];
for (int i = ; i <= word1.Length; i++)
{
for (int j = ; j <= word2.Length; j++)
{
if (i == || j == ) dp[i, j] = ;
else dp[i, j] = (word1[i - ] == word2[j - ]) ? dp[i - , j - ] +
: Math.Max(dp[i - , j], dp[i, j - ]);
}
}
int val = dp[word1.Length, word2.Length];
return word1.Length - val + word2.Length - val;
}
}

https://leetcode.com/problems/delete-operation-for-two-strings/#/solutions

思路:本题使用动态规划,将问题转化为求:最长公共子序列。

leetcode583的更多相关文章

  1. [Swift]LeetCode583. 两个字符串的删除操作 | Delete Operation for Two Strings

    Given two words word1 and word2, find the minimum number of steps required to make word1 and word2 t ...

随机推荐

  1. [转载]java向word模板中填充数据(总结)

    使用过PageOffice动态生成word文档的人都知道,PageOffice可以给word文档的指定位置进行填充,这里我们所说的指定位置在PageOffice的专业术语里面有两个概念,一个叫做数据区 ...

  2. docker-web管理工具实验

    工具名称 共有功能 备注 UCP   官方.收费 portainer 镜像库 容器管理   rancher   shipyard   kubernetes     (上诉部署都基于linux) UCP ...

  3. node 一站式 学习 教程

    还是比较全面的, 包括了 : monogoDB的安装 使用 , 各种插件, 中间件的介绍, 路由的介绍, 各种数据库框架的介绍, 测试介绍;  掌握后应该可以开发一个中型的程序, 大型程序因为有性能的 ...

  4. I.MX6 AR8031 寄存器操作

    /*************************************************************************** * I.MX6 AR8031 寄存器操作 * ...

  5. 深入了解zookeeper(三)

    一.ZooKeeper 的实现 1.1 ZooKeeper处理单点故障 我们知道可以通过ZooKeeper对分布式系统进行Master选举,来解决分布式系统的单点故障,如图所示. 那么我们继续分析一下 ...

  6. N位N进制里有多少个N

    32位二进制里有多少个1 https://blog.csdn.net/zhangsj1007/article/details/81411063 有这样一道计算机问题"32位二进制里面有多少个 ...

  7. C# 数组、ArrayList和List三者的区别

    在C#中数组,ArrayList,List都能够存储一组对象,那么这三者到底有什么样的区别呢. 数组 数组在C#中最早出现的.在内存中是连续存储的,所以它的索引速度非常快,而且赋值与修改元素也很简单. ...

  8. 程序4-2 access函数实例

    //http://blog.chinaunix.net/uid-24549279-id-71355.html /* ========================================== ...

  9. J-Link在SWD模式与MCU能连接成功但不能读写

    今天在J-Link的排线末端引出3.3v.SWDIO.SWCLK.GND,连接到stm32上,发现只能连接成功,不能读和写,出现下面错误: - ERROR: RAM check failed @ ad ...

  10. delphi 线程的使用

    unit untWorkThread; interface uses Windows,Classes,SysUtils; type TWorkItem=class end; TProcessWork= ...