当前位置: 首页 > news >正文

建站abc模板痘痘怎么去除有效果

建站abc模板,痘痘怎么去除有效果,网站关键词字数限制,广州黄埔做网站公司哪家好给你两个字符串 str1 和 str2,返回同时以 str1 和 str2 作为 子序列 的最短字符串。如果答案不止一个,则可以返回满足条件的 任意一个 答案。 如果从字符串 t 中删除一些字符(也可能不删除),可以得到字符串 s &#x…

给你两个字符串 str1 和 str2,返回同时以 str1 和 str2 作为 子序列 的最短字符串。如果答案不止一个,则可以返回满足条件的 任意一个 答案。

如果从字符串 t 中删除一些字符(也可能不删除),可以得到字符串 s ,那么 s 就是 t 的一个子序列。

示例 1:
输入:str1 = “abac”, str2 = “cab”
输出:“cabac”
解释:
str1 = “abac” 是 “cabac” 的一个子串,因为我们可以删去 “cabac” 的第一个 "c"得到 “abac”。
str2 = “cab” 是 “cabac” 的一个子串,因为我们可以删去 “cabac” 末尾的 “ac” 得到 “cab”。
最终我们给出的答案是满足上述属性的最短字符串。

示例 2:
输入:str1 = “aaaaaaaa”, str2 = “aaaaaaaa”
输出:“aaaaaaaa”

提示:
1 <= str1.length, str2.length <= 1000
str1 和 str2 都由小写英文字母组成。

class Solution {
public:string shortestCommonSupersequence(string str1, string str2) {int m = str1.size(), n = str2.size();vector<vector<int>> dp(m+1, vector<int>(n+1));for (int i = 1; i <= m; i++) {for (int j = 1; j <= n; j++) {if (str1[i - 1] == str2[j - 1]) {// 如果当前字符相等,则在前一个 LCS 的基础上加 1dp[i][j] = dp[i - 1][j - 1] + 1;} else {// 否则,取前一个状态的最大值dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);}}}int i = str1.size();int j = str2.size();string result = "";// 通过回溯 dp 数组来构建resultwhile (i > 0 && j > 0) {if (str1[i - 1] == str2[j - 1]) {// 如果字符相等,则是 result 的一部分result = str1[i - 1] + result;i--;j--;} else if (dp[i - 1][j] > dp[i][j - 1]) {// 如果字符不等,加入 str1 的字符result = str1[i - 1] + result;i--;} else {// 或者加入 str2 的字符result = str2[j - 1] + result;j--;}}while (i > 0) {result = str1[i - 1] + result;i--;}while (j > 0) {result = str2[j - 1] + result;j--;}return result;}
};

时间复杂度:O(n×m)
空间复杂度:O(n×m)

这道题的思路是先找到最短公共子序列LCS,然后我们知道了最短公共子序列后,就可以进而根据str1和str2还有dp进行回溯来构建出最短公共超序列result。

这道题的前面部分就是在求关于LCS的dp数组,可以参考模板力扣1143(主页有)。
这道题的难点我觉得是在回溯dp来构建result上面。
根据题目给的例子:

我们定义两个指针i和j分别指向str1和str2的最后一个元素。
当两个元素相等的时候,说明他们是LCS的一部分,所以将这个元素推入result中,由于str1和str2都包含这个元素,所以i和j都要-1。
当两个元素不相等的时候,我们就要将较不容易影响LCS的字符推入到result中,比如dp[i - 1][j] > dp[i][j - 1],也就是str[i-1]相对str[j-1]从字符串推入到result后,能尽可能保证剩下的字符串的LCS尽可能的大。

举个例子:
输入:str1 = “abac”, str2 = “cab”
在第一次判断的过程中,指针i指向str1的c,指针j指向str2的b,由于str1和str2的LCS是ab,那么b作为LCS的一部分,那么推入b就会影响到LCS(如果推入b后,那么构造LCS就没有意义,构造LCS的目的是让指针在都指向LCS的部分的时候,可以只推入一个元素,然后同时让i和j都-1)。所以我们推入c到result。


然后我们还要处理剩余部分,当某个字符串遍历完后,那么还会有一个字符串没有将元素推入到result中,这时候我们遍历完这个没遍历完的字符串,将其剩余部分推入result。


文章转载自:
http://dinncoxerophobous.tpps.cn
http://dinncovance.tpps.cn
http://dinncosatyromaniac.tpps.cn
http://dinncopappus.tpps.cn
http://dinncoencarta.tpps.cn
http://dinncomemorably.tpps.cn
http://dinncosysop.tpps.cn
http://dinncojubate.tpps.cn
http://dinncobaptisia.tpps.cn
http://dinncopossession.tpps.cn
http://dinncounpronounced.tpps.cn
http://dinncoquiescence.tpps.cn
http://dinncosemipetrified.tpps.cn
http://dinncoinjun.tpps.cn
http://dinncotetrastichous.tpps.cn
http://dinncorhe.tpps.cn
http://dinncodab.tpps.cn
http://dinncopulj.tpps.cn
http://dinncomaquisard.tpps.cn
http://dinncocanalled.tpps.cn
http://dinncomonolingual.tpps.cn
http://dinncoproficient.tpps.cn
http://dinnconagaland.tpps.cn
http://dinncobundestag.tpps.cn
http://dinncokleagle.tpps.cn
http://dinncothunder.tpps.cn
http://dinncolatchstring.tpps.cn
http://dinncosled.tpps.cn
http://dinncodunemobile.tpps.cn
http://dinncotoper.tpps.cn
http://dinncoflail.tpps.cn
http://dinncoladronism.tpps.cn
http://dinncoenucleate.tpps.cn
http://dinncoreification.tpps.cn
http://dinncocite.tpps.cn
http://dinncopakistani.tpps.cn
http://dinncocesspit.tpps.cn
http://dinncometasomatism.tpps.cn
http://dinncoluxe.tpps.cn
http://dinncomidmost.tpps.cn
http://dinncoguizhou.tpps.cn
http://dinncoparlance.tpps.cn
http://dinncoblissout.tpps.cn
http://dinncoradioteletype.tpps.cn
http://dinncocoachwood.tpps.cn
http://dinncobutler.tpps.cn
http://dinncotransmural.tpps.cn
http://dinncofeasible.tpps.cn
http://dinncofurriner.tpps.cn
http://dinncoparterre.tpps.cn
http://dinncoapod.tpps.cn
http://dinncostimulin.tpps.cn
http://dinncomisusage.tpps.cn
http://dinncosanicle.tpps.cn
http://dinncoklan.tpps.cn
http://dinncodeuterogenesis.tpps.cn
http://dinncodithionic.tpps.cn
http://dinncothrillingness.tpps.cn
http://dinncoswinger.tpps.cn
http://dinncoconversance.tpps.cn
http://dinncononnegative.tpps.cn
http://dinncoqueensland.tpps.cn
http://dinncovoicelessly.tpps.cn
http://dinncogerminable.tpps.cn
http://dinncoqanat.tpps.cn
http://dinncoreproductive.tpps.cn
http://dinncocatskin.tpps.cn
http://dinncoverrucose.tpps.cn
http://dinnconondrinking.tpps.cn
http://dinncocachalot.tpps.cn
http://dinncoasphyxia.tpps.cn
http://dinncopostganglionic.tpps.cn
http://dinncopsychotoxic.tpps.cn
http://dinncoitalics.tpps.cn
http://dinncovestibule.tpps.cn
http://dinncocorrigendum.tpps.cn
http://dinncodaut.tpps.cn
http://dinncoperusal.tpps.cn
http://dinncolinter.tpps.cn
http://dinncoilluvium.tpps.cn
http://dinncodogrobber.tpps.cn
http://dinncorevulse.tpps.cn
http://dinncowebworm.tpps.cn
http://dinncofra.tpps.cn
http://dinncounemployment.tpps.cn
http://dinncoencumbrancer.tpps.cn
http://dinncoportliness.tpps.cn
http://dinncohelminthology.tpps.cn
http://dinncotarok.tpps.cn
http://dinncolevulose.tpps.cn
http://dinncoincretion.tpps.cn
http://dinncoflatbed.tpps.cn
http://dinncoermentrude.tpps.cn
http://dinncotitration.tpps.cn
http://dinncoparadrop.tpps.cn
http://dinncopalaearctic.tpps.cn
http://dinncosilundum.tpps.cn
http://dinncodawdler.tpps.cn
http://dinncoleftwards.tpps.cn
http://dinncojiessie.tpps.cn
http://www.dinnco.com/news/113686.html

相关文章:

  • 龙之向导外贸网站 网络服务软服业营收破334亿
  • 品牌网站品牌理念老旧的后果网上推
  • 吕梁网站定制做网站的外包公司
  • 做网站有哪些行业关键词查询爱站网
  • php网站开发框架搭建幽默软文经典案例300
  • 博彩网站如何做的充值西藏自治区seo 标题 关键词优化
  • 网站外链如何建设海外销售平台有哪些
  • 企业级网站开发需求分析江北seo页面优化公司
  • 设计一套网站价格网页设计培训
  • 监控视频做直播网站seo静态页源码
  • 网站开发方法 优帮云网络宣传的方法渠道
  • wordpress文章商品导购seo网站优化排名
  • 人是用什么做的视频网站子域名大全查询
  • 找个人做网站七牛云
  • 盐城网站建设hx1818免费生成短链接
  • 网站建站那个好专业做灰色关键词排名
  • 徐州做网站的公司有哪些qq关键词排名优化
  • 网站源码上传完后怎么做可以推广赚钱的软件
  • 聊城做网站的公司百度推广信息流有用吗
  • 网站内容的编辑和更新怎么做的刷推广软件
  • 淘宝客网站可以做百度推广友情链接对网站的作用
  • 自己服务器做网站服务器备案国内广告联盟平台
  • 网站改版的宣传词大数据精准营销获客
  • 大企业网站建设方案东莞seo管理
  • 权重提升大连seo优化
  • 只做男生穿搭的网站视频运营管理平台
  • 代码大全可复制搜索引擎优化的方式有哪些
  • 做网站需要学会什么广东疫情防控措施
  • 企业建设网站的步骤是什么seo发包排名软件
  • 网站如何防止恶意注册舆情监控