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. 【lightoj-1063】Ant Hills(求割点)

    求割点模板题 #include <bits/stdc++.h> using namespace std; const int N = 10004; int dfn[N], low[N]; ...

  2. Django与数据库操作

    Django与数据库操作 数据库连接的方法 web 框架 django --- 自己内部实现 (ORM) + pymysql(连接) Flask,tornado --- pymysql SQLArch ...

  3. 打印机无法使用且无法重新安装,提示spooler service is not running

    使用场景:之前安装好的打印服务今天突然无法使用,列表里面找不到打印机,于是重新安装,得到以下错误: The local print spooler service is not running. Pl ...

  4. C++11中提供了std::bind

    再来看看std::bind C++11中提供了std::bind.bind()函数的意义就像它的函数名一样,是用来绑定函数调用的某些参数的. bind的思想实际上是一种延迟计算的思想,将可调用对象保存 ...

  5. C语言中的extern关键字用法

    在C语言中,修饰符extern用在变量或者函数的声明前,用来说明“此变量/函数是在别处定义的,要在此处引用”. 1. extern修饰变量的声明.举例来说,如果文件a.c需要引用b.c中变量int v ...

  6. 你必须知道的495个C语言问题,学习体会二

    这是本主题的第二篇文章,主要就结构体,枚举.联合体做一些解释 1.结构体 现代C语言编程 结构化的基石,diy时代的最好代言人,是面向对象编程中类的老祖宗. 我们很容易定义一个结构体,比如学生: st ...

  7. POJ1287 Networking

    解题思路:Kruskal模板题,重复输入的情况,本题是无向图. 见代码: #include<cstdio> #include<algorithm> #include<cs ...

  8. HihoCoder 1067 最近公共祖先(ST离线算法)

    最近公共祖先·二 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 上上回说到,小Hi和小Ho用非常拙劣——或者说粗糙的手段山寨出了一个神奇的网站,这个网站可以计算出某两个 ...

  9. IntelliJ IDEA 安装破解详解

    https://github.com/tengj/IntelliJ-IDEA-Tutorial IntelliJ IDEA官方中文文档 https://blog.csdn.net/newabcc/ar ...

  10. 分布式使用Redis

    为什么我们做分布式使用Redis? https://www.cnblogs.com/yaodengyan/p/9717080.html 绝大部分写业务的程序员,在实际开发中使用 Redis 的时候,只 ...