LeetCode 583 Delete Operation for Two Strings 删除两个字符串的不同部分使两个字符串相同,求删除的步数
Given two words word1 and word2, find the minimum number of steps required to make word1 and word2 the same, where in each step you can delete one character in either string.
Example 1:
Input: "sea", "eat"
Output: 2
Explanation: You need one step to make "sea" to "ea" and another step to make "eat" to "ea".
Note:
1.The length of given words won't exceed 500.
2.Characters in given words can only be lower-case letters.
class Solution {
public:
int minDistance(string word1, string word2) {
int n1=word1.size();
int n2=word2.size();
int dp[n1+][n2+]; for(int i=;i<=n1;++i)
{
for(int j=;j<=n2;++j)
{
if(i==||j==)
dp[i][j]=;
else
{
if(word1[i-]==word2[j-])
dp[i][j]=dp[i-][j-]+;
else
dp[i][j]=max(dp[i-][j],dp[i][j-]);
}
}
}
return n1+n2-dp[n1][n2]*;
}
};
LeetCode 583 Delete Operation for Two Strings 删除两个字符串的不同部分使两个字符串相同,求删除的步数的更多相关文章
- [LeetCode] 583. Delete Operation for Two Strings 两个字符串的删除操作
Given two words word1 and word2, find the minimum number of steps required to make word1 and word2 t ...
- 【Leetcode】583. Delete Operation for Two Strings
583. Delete Operation for Two Strings Given two words word1 and word2, find the minimum number of st ...
- LC 583. Delete Operation for Two Strings
Given two words word1 and word2, find the minimum number of steps required to make word1 and word2 t ...
- 【LeetCode】583. Delete Operation for Two Strings 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 583. Delete Operation for Two Strings
Given two words word1 and word2, find the minimum number of steps required to make word1 and word2 t ...
- [LeetCode] Delete Operation for Two Strings 两个字符串的删除操作
Given two words word1 and word2, find the minimum number of steps required to make word1 and word2 t ...
- LeetCode Delete Operation for Two Strings
原题链接在这里:https://leetcode.com/problems/delete-operation-for-two-strings/description/ 题目: Given two wo ...
- [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 ...
- [LeetCode] 712. Minimum ASCII Delete Sum for Two Strings 两个字符串的最小ASCII删除和
Given two strings s1, s2, find the lowest ASCII sum of deleted characters to make two strings equal. ...
随机推荐
- 数据结构-二叉搜索树的js实现
一.树的相关概念 1.基本概念 子树 一个子树由一个节点和它的后代构成. 节点的度 节点所拥有的子树的个数. 树的度 树中各节点度的最大值 节点的深度 节点的深度等于祖先节点的数量 树的高度 树的高度 ...
- 找工作-——网络IO
网络层 主要任务是把网络协议数据单元或分组从源计算机经过适当的路径发送到目的地计算机.从源计算机到目的计算机可能要经过若干个中间节点,这需要在通信子网中进行路由选择. 网络层与数据链路层有很大的差别, ...
- mac下无法远程桌面连接win10的解决办法
原文链接:http://www.hangge.com/blog/cache/detail_899.html 原来在Mac OSX下远程win7系统很正常,后来把windows系统升级成了win10,再 ...
- Linux根据端口查看进程
若不知道具体目录,可以根据端口查找,查看端口22000的信息: sudo lsof -i:22000 RelaySvr 4322 root 13u IPv4 75680495 0t0 ...
- 用户收到"无法显示页面"的错误消息和"Connections_refused"条目记录在运行 Windows Server 2003,Exchange 2003 和 IIS 6.0 的服务器上的 Httperr.log 文件
症状 您会遇到下列症状在运行 Microsoft Windows Server 2003. Microsoft Exchange Server 2003年和 Microsoft Internet In ...
- 集合对象与自定义javabean对象接收数据库查询的数据 (基础知识扫盲)
一.集合对象(List,Map,数组)等对象接收数据库查询的记录,如果没有一条记录,就得到的内容为空的集合,不是null: 例如:List查不到记录得到的就是size=0的list 二.自定义的jav ...
- python 基础 列表 增删改查
names = ["aaron", "alex", "james", "meihengfan"]names2 = [1, ...
- linux 下 安装mysql
安装之前,因为redhat 是yum自带的,但是不能使用,因为要交钱,还要订阅,所以需要卸载,重新安装163提供的yum 在另外一篇文章介绍 yum list mysql* 列出所有关于mysal的安 ...
- centos7 安装mysql 5.7多实例
一. Mysql多实例即一台服务器上运行多个Mysql服务进程 ,开启不同的服务端口,通过不同的socket 监听不同的服务端口来提供各自的服务. 二. Mysql多例有以下几个特点: 1. 有效利 ...
- IoC概述
---------------siwuxie095 IoC,即 Inversion of Control,控制反转,它是 Spring 容器的内核 AOP.声明式事务等功能都是在此基础上开花结果,即 ...