leetcode583
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的更多相关文章
- [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 ...
随机推荐
- 20165210 Java第四次实验报告
20165210 实验四 Android程序设计 实验步骤 第24章:初识Android 任务一:完成Hello World, 要求修改res目录中的内容,Hello World后要显示自己的学号 学 ...
- 2017.11.16 STM8L052 温度控制器
1 J-link和ST-link的兼容性 STM8只能用ST-link.J-link兼容所有的(大部分而已)的ARM内核IC mark: http://bbs.eeworld.com.cn/thre ...
- poscms仿站知识点总结(二)
1.相同类型div添加不同class 遇到一个样式上的问题,模板页面有8个子项,样式都是一样,至于数据是可以用for循环来添加的,但是for循环的时候,每个div的 类名是无法及时更改的,但是模板页面 ...
- 一个 token 控件
用于以分词形式显示某个对象的多个标签,比如: 用法 将 TagsView.h/.m 文件拷贝到你的项目文件夹,在需要用到该控件的地方导入 TagsView.h 头文件. IB 中的工作 拖一个 UIV ...
- bzoj 2131 免费的馅饼
Written with StackEdit. Description Input 第一行是用空格隔开的二个正整数,分别给出了舞台的宽度\(W\)(\(1\)到\(10^8\)之间)和馅饼的个数\(n ...
- NSArray倒序输出的方法
NSMutableArray *array = [NSMutableArray arrayWithObjects:",nil]; NSArray* reversedArray = [[arr ...
- minio nginx 配置
1. 参考配置 server { listen 80; server_name example.com; location / { proxy_set_header Host $http_host; ...
- c&c++ datetime
时间函数之间的关系 struct tm { int tm_sec; // 代表目前秒数,正常范围0-59,但允许至61秒: int tm_min; // 代表目前分数,范围为0-59. int tm_ ...
- Unity GUI自适应屏幕分辨率(一)布局自适应
这里我们先谈第一个问题坐标矩阵变化实现布局自适应. 选取基准尺寸 通常你需要选择一个基准的屏幕尺寸,象现在开发的应用也需要跨平台在iOS(iPhone/iPad)/Android都可以运行,我这边选取 ...
- lnmp php7 安装mysqli扩展 undefined function mysqli_connect()
在用ci框架的时候, https://blog.csdn.net/zqtsx/article/details/8746497 https://blog.csdn.net/move_now/articl ...