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. NAVagationController

    UINavigationController为导航控制器,在iOS里经常用到. 1.UINavigationController的结构组成 UINavigationController有Navigat ...

  2. antd-iconfont for inner network

    npm install antd-iconfont --save npm install less less-loader --save-dev webpack.config.js const pat ...

  3. Chrome字体变粗

    如图.解决方案,看看CSS中用了什么字体,卸载某个字体. 因为我装了一个新的字体,CSS中有这个字体的网页都会变粗.删掉这个字体就恢复正常了

  4. Http权威指南(TCP连接)

    1.HTTP请求的过程 世界上几乎所有的HTTP通信都是由TCP/IP承载的,当发生HTTP请求时,实际上经过了以下几个步骤: ①浏览器从请求的URL中解析主机名 ②浏览器查询这个主机名的IP地址 ③ ...

  5. Java进阶面试问题列表

    面向对象编程的基本理念与核心设计思想 解释下多态性(polymorphism),封装性(encapsulation),内聚(cohesion)以及耦合(coupling). 继承(Inheritanc ...

  6. C# 通过窗口句柄获取程序路径 图标

    转自:http://qqhack8.blog.163.com/blog/static/11414798520113363829505/ C# 通过窗口句柄获取程序路径 图标using System;u ...

  7. strftime()和strptime的区别

    strftime()是把时间转成规定格式的字符串 strptime()是把字符串转成时间 转载:http://blog.csdn.net/caimouse/article/details/501986 ...

  8. 关于ORM,以及Python中SQLAlchemy的sessionmaker,scoped_session

    orm(object relational mapping):对象关系映射. python面向对象,而数据库是关系型. orm是将数据库关系映射为Python中的对象,不用直接写SQL. 缺点是性能略 ...

  9. WPF简单模拟QQ登录背景动画(转)

    介绍 之所以说是简单模拟,是因为我不知道QQ登录背景动画是怎么实现的.这里是通过一些办法把它简化了,做成了类似的效果 效果图 大体思路 首先把背景看成是一个4行8列的点的阵距,X轴Y轴都是距离70.把 ...

  10. datasnap 上传/下载大文件(本Demo以图传片文件为例)

    好久没写技术文了 datasnap传大流. 完整代码,同时感谢叶兄传流的指点,(只公开十天) 附:下面代码,转载请注明出处 ::code 服务端: function TServerMethods1.D ...