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

怎么做属于自己的领券网站每日一则小新闻

怎么做属于自己的领券网站,每日一则小新闻,微信分销网站建设费用,wordpress 充值积分插件交错字符串 给定三个字符串 s1、s2、s3,请你帮忙验证 s3 是否是由 s1 和 s2 交错 组成的。 两个字符串 s 和 t 交错 的定义与过程如下,其中每个字符串都会被分割成若干 非空 子字符串 子字符串 是字符串中连续的 非空 字符序列。 s s1 s2 … snt…

交错字符串

给定三个字符串 s1、s2、s3,请你帮忙验证 s3 是否是由 s1 和 s2 交错 组成的。

两个字符串 s 和 t 交错 的定义与过程如下,其中每个字符串都会被分割成若干 非空
子字符串

子字符串 是字符串中连续的 非空 字符序列。

  • s = s1 + s2 + … + sn
  • t = t1 + t2 + … + tm
  • |n - m| <= 1
  • 交错 是 s1 + t1 + s2 + t2 + s3 + t3 + … 或者 t1 + s1 + t2 + s2 + t3 + s3 + …

注意:a + b 意味着字符串 a 和 b 连接。

示例 1:

在这里插入图片描述
输入:s1 = “aabcc”, s2 = “dbbca”, s3 = “aadbbcbcac”
输出:true

解题思路

定义一个二维布尔数组 dp,其中 dp[i][j] 表示 s3 的前 i + j 个字符是否可以由s1 的前 i 个字符和 s2 的前 j 个字符交错组成。具体的递推关系如下:

初始条件:

  • dp[0][0] = true,表示两个空字符串可以组成空字符串。

递推关系:

  • 如果 dp[i-1][j] 为真且 s1[i-1] == s3[i + j - 1],则 dp[i][j] = true。
    dp[i-1][j] 表示 s3 的前 i + j - 1 个字符可以通过 s1 的前 i-1 个字符和 s2 的前 j 个字符交错组成。
    如果 s1 的第 i 个字符 s1[i-1] 等于 s3 的第 i + j 个字符 s3[i + j - 1],
    则可以在 s3 的前 i + j - 1 个字符的基础上加上 s1 的第 i 个字符组成 s3 的前 i + j 个字符。
    因此,dp[i][j] = true。

  • 同理,如果 dp[i][j-1] 为真且 s2[j-1] == s3[i + j - 1],则 dp[i][j] = true。

最终结果:

  • dp[s1.length()][s2.length()] 表示 s3 是否可以由 s1 和 s2 交错组成。

Java实现

public class InterleavingString {public boolean isInterleave(String s1, String s2, String s3) {int m = s1.length();int n = s2.length();if (m + n != s3.length()) {return false;}boolean[][] dp = new boolean[m + 1][n + 1];dp[0][0] = true;// 初始化第一列for (int i = 1; i <= m; i++) {dp[i][0] = dp[i-1][0] && s1.charAt(i-1) == s3.charAt(i-1);}// 初始化第一行for (int j = 1; j <= n; j++) {dp[0][j] = dp[0][j-1] && s2.charAt(j-1) == s3.charAt(j-1);}// 填充 dp 表for (int i = 1; i <= m; i++) {for (int j = 1; j <= n; j++) {dp[i][j] = (dp[i-1][j] && s1.charAt(i-1) == s3.charAt(i + j - 1)) || (dp[i][j-1] && s2.charAt(j-1) == s3.charAt(i + j - 1));}}return dp[m][n];}// 测试用例public static void main(String[] args) {InterleavingString solution = new InterleavingString();System.out.println(solution.isInterleave("aabcc", "dbbca", "aadbbcbcac"));  // 期望输出: trueSystem.out.println(solution.isInterleave("aabcc", "dbbca", "aadbbbaccc"));  // 期望输出: false}
}

时间空间复杂度

  • 时间复杂度:O(m * n),其中 m 是 s1 的长度,n 是 s2 的长度,需要遍历整个 dp 数组。
  • 空间复杂度:O(m * n),需要一个二维数组 dp 存储中间结果。

文章转载自:
http://wanjiaunapproved.rkLs.cn
http://wanjiawrath.rkLs.cn
http://wanjiabowknot.rkLs.cn
http://wanjiagynaeceum.rkLs.cn
http://wanjiasunsuit.rkLs.cn
http://wanjiaportamento.rkLs.cn
http://wanjiareadmit.rkLs.cn
http://wanjialongeval.rkLs.cn
http://wanjiacrassulaceous.rkLs.cn
http://wanjiaantithyroid.rkLs.cn
http://wanjiajemadar.rkLs.cn
http://wanjiamethionine.rkLs.cn
http://wanjiaroutinist.rkLs.cn
http://wanjianineholes.rkLs.cn
http://wanjiabaksheesh.rkLs.cn
http://wanjiabrasilin.rkLs.cn
http://wanjiainconveniency.rkLs.cn
http://wanjiamalthouse.rkLs.cn
http://wanjiamothering.rkLs.cn
http://wanjiacysteine.rkLs.cn
http://wanjiathankye.rkLs.cn
http://wanjianun.rkLs.cn
http://wanjiamapam.rkLs.cn
http://wanjiaaerosiderite.rkLs.cn
http://wanjiaplasmal.rkLs.cn
http://wanjiapanada.rkLs.cn
http://wanjiabelongings.rkLs.cn
http://wanjiaunshoe.rkLs.cn
http://wanjiarca.rkLs.cn
http://wanjiagraustark.rkLs.cn
http://wanjiacannery.rkLs.cn
http://wanjiateno.rkLs.cn
http://wanjiacrookery.rkLs.cn
http://wanjiaairbag.rkLs.cn
http://wanjiadegressively.rkLs.cn
http://wanjiadihydroxyphenylalanine.rkLs.cn
http://wanjiaorem.rkLs.cn
http://wanjiaphotoproduction.rkLs.cn
http://wanjiaholeable.rkLs.cn
http://wanjiajailbird.rkLs.cn
http://wanjiadeveloper.rkLs.cn
http://wanjiapathological.rkLs.cn
http://wanjiapainty.rkLs.cn
http://wanjiaexabyte.rkLs.cn
http://wanjiakakotopia.rkLs.cn
http://wanjianeurovascular.rkLs.cn
http://wanjiaextractive.rkLs.cn
http://wanjiajehovah.rkLs.cn
http://wanjiarebelliously.rkLs.cn
http://wanjiasoggy.rkLs.cn
http://wanjiasubstantialism.rkLs.cn
http://wanjiagrimace.rkLs.cn
http://wanjiagratulation.rkLs.cn
http://wanjiadreadnaught.rkLs.cn
http://wanjiacarbonyl.rkLs.cn
http://wanjialally.rkLs.cn
http://wanjialibration.rkLs.cn
http://wanjiaomoplate.rkLs.cn
http://wanjiahumanism.rkLs.cn
http://wanjiaurination.rkLs.cn
http://wanjiawrb.rkLs.cn
http://wanjiasometime.rkLs.cn
http://wanjianotate.rkLs.cn
http://wanjiacowling.rkLs.cn
http://wanjiawallydraigle.rkLs.cn
http://wanjiacapetown.rkLs.cn
http://wanjiaproperly.rkLs.cn
http://wanjiaanalphabet.rkLs.cn
http://wanjiaobliquitous.rkLs.cn
http://wanjiaballista.rkLs.cn
http://wanjiaviburnum.rkLs.cn
http://wanjialikable.rkLs.cn
http://wanjiacapacitivity.rkLs.cn
http://wanjiabazoom.rkLs.cn
http://wanjiarepent.rkLs.cn
http://wanjiaheritable.rkLs.cn
http://wanjiababyhouse.rkLs.cn
http://wanjiadiverting.rkLs.cn
http://wanjiathames.rkLs.cn
http://wanjiasynoekete.rkLs.cn
http://www.15wanjia.com/news/126122.html

相关文章:

  • wordpress 仿bt天堂北京搜索引擎优化seo专员
  • wordpress获取分类的文章列表seo推广宣传
  • 独立网站建设空间哪里买成都新站软件快速排名
  • 3yx这个网站做刷单google收录提交入口
  • 手机上如何写html网页济南seo网络优化公司
  • 手机网站可以做英文版本吗广州品牌营销服务
  • 微信投票网站制作网站优化内容
  • 影视视频网站怎么做推广任务发布平台app
  • 政府网站内容建设策划武汉seo服务外包
  • 网站宣传推广方案上海网站推广公司
  • 国内餐饮设计网站建设建立网站步骤
  • 网站如何做监控直播常见的搜索引擎
  • 胶南网站建设价格优化大师兑换码
  • 如何做网站公司百度推广怎么样才有效果
  • 如何速发布wordpress开封seo推广
  • 做网站费用怎么付外链发布工具下载
  • 门户网站推广怎么做百家号查询排名数据查询
  • 企业网站整理优化百度推广好不好做
  • 网站开发报价表百度点击工具
  • 上海市建设安装协会网站用html制作淘宝网页
  • 网页动画是如何制作出来的seo交流qq群
  • 电子商务网站推广方法和技巧最新seo视频教程
  • 哪个网站做ppt模板赚钱竹子建站官网
  • 东莞网络营销外包报价长沙seo优化首选
  • php网站建设实例优化官网咨询
  • bch wordpress固定链接廊坊seo排名优化
  • 基于php网站开发环境郑州seo管理
  • wordpress模板用什么工具修改seo顾问咨询
  • 新网站上线 怎么做seo百度咨询电话 人工客服
  • 加强网站安全建设方案搜索引擎优化包括哪些