1. 是一个很明显的动态规划题。

2. s3中的每个字符不是s1中的就是s2中的,只要根据它之前的状态做转移就可以。

 1 class Solution {
 2 public:
 3     bool isInterleave(string s1, string s2, string s3) {
 4         int n = s1.size();
 5         int m = s2.size();
 6         if (n + m != s3.size()) return false;
 7         vector<vector<int>> f(n+1, vector<int>(m+1));
 8         for (int i = 0; i <= n; i++) {
 9             for (int j = 0; j <= m; j++) {
10                 int idx = i + j - 1;
11                 if (i == 0 && j == 0) {
12                     f[i][j] = 1;
13                 } else {
14                     if (i && s1[i-1] == s3[idx]) f[i][j] |= f[i-1][j];
15                     if (j && s2[j-1] == s3[idx]) f[i][j] |= f[i][j-1];
16                 }
17             }
18         }
19         return f[n][m];
20     }
21 };

转载于:https://www.cnblogs.com/zeeroo32/p/6493281.html

[LeetCode] Interleaving String相关推荐

  1. LeetCode Interleaving String(动态规划)

    Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example, Given: s1 ...

  2. leetcode - Interleaving String

    Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example, Given: s1 ...

  3. LeetCode Interleaving String

    原题链接在这里:https://leetcode.com/problems/interleaving-string/ 这是一道DP题,用boolean数组dp维护历史数据,dp[i][j]表示长度为i ...

  4. 【重点!DP】LeetCode 97. Interleaving String

    LeetCode 97. Interleaving String 参考网址:[1]https://www.youtube.com/watch?v=HmAF9xeS_2I [2]http://www.c ...

  5. 【细节实现题】LeetCode 8. String to Integer (atoi)

    LeetCode 8. String to Integer (atoi) Solution1:我的答案 参考链接:http://www.cnblogs.com/grandyang/p/4125537. ...

  6. LeetCode 8. String to Integer (atoi)(字符串)

    LeetCode 8. String to Integer (atoi)(字符串) LeetCode 8 String to Integer atoi字符串 问题描述 解题思路 参考代码 By Sca ...

  7. 【leetcode】97. Interleaving String

    题目如下: 解题思路:本题可以采用动态规划的方法.记dp[i][j]表示用s1的前i个字符和s2的前j个字符能否组成s3的前(i+j)个字符,如果dp[i-1][j]是True的话,只要s1[i] = ...

  8. leetcode解题报告:Interleaving String

    问题描述: 给定两个字符串s1, s2,判断字符串s3是否是由s1.s2交错构成. 例子: s1 = "aabcc", s2 = "dbbca", When s ...

  9. LeetCode Scramble String

    LeetCode解题之Scramble String 原题 一个字符串能够拆分成两个都不为空的子字符串,而子字符串(长度大于等于二)也能够不断这样拆分下去.如今能够随意交换拆分出来两部分的位置来改变字 ...

最新文章

  1. 30分钟内让你明白正则表达式是什么,并对它有一些基本的了解(二)
  2. jQuery的Growl插件
  3. TensorFlow2-神经网络基础
  4. IOS之Swift5.x和OC网络请求JSON
  5. 出国?上研?工作?回家种田?(三) IT类专业的工作方向与特点(软硬件技术等岗位)
  6. java高分面试指南:java定时删除文件
  7. for循环里面有异步操作_JS 线程与异步的那些事
  8. 哇!单细胞测序-配体受体互作分析原来可以这么简单又高大上!
  9. 华为机试HJ74:参数解析
  10. 157. PHP 闭标签
  11. 向数据源DataTable 中添加新的一列,并向其赋值
  12. Oracle RAC tns 00505,Alert Log Errors: 12170 TNS-12535/TNS-00505: Operation Timed Out
  13. 2020年百度之星程序设计大赛-初赛一(Drink、GPA、Dec)
  14. 论文《基于FPGA 的CFAR 设计与实现》复现
  15. Google 2018 IO 大会要点
  16. 中棉所建议国家扶持棉花产业
  17. 解决win10访问xp服务器共享文件出现smb1问题
  18. 倪光南院士:构建安全可控的信息技术体系,云宏高安全的云计算关键核心技术先行
  19. photoshop颈纹去除
  20. 缺失数据的Bootstrap与Jackknife方法:《Statistical Analysis with Missing Data》习题5.1 5.2

热门文章

  1. 学生管理系统java mysql_学生信息管理系统 基于Java+mysql开发的学生管理系统 - 下载 - 搜珍网...
  2. 着墨中文lisp登入_Lisp的本质 - climbdream的个人空间 - OSCHINA - 中文开源技术交流社区...
  3. oracle sequrnce_Oracle Sqlldr简单用法
  4. 数据结构--链式栈--C++实现
  5. POJ3614防晒霜 这个贪心有点东西(贪心+优先队列)
  6. 浅谈bash shell的种类以及linux系统中的profile和bashrc配置文件
  7. Servlet3 -- Servlet异步处理
  8. python画交互式地图_使用Python构建交互式地图-入门指南
  9. visual c++ build tools的安装与使用
  10. 芝麻信用分750以上有什么特殊作用?