[LeetCode] Interleaving String
来源:互联网 发布:域名区别 编辑:程序博客网 时间:2024/05/01 10:07
class Solution {public: bool isInterleave(string s1, string s2, string s3) { // Start typing your C/C++ solution below // DO NOT write int main() function int m = s1.size(); int n = s2.size(); if (m + n != s3.size()) return false; vector<vector<int> > dp(m + 1, vector<int>(n + 1)); dp[0][0] = true; for (int i = 1; i <= m; i++) { dp[i][0] = dp[i - 1][0] && (s1[i - 1] == s3[i - 1]); } for (int j = 1; j <= n; j++) { dp[0][j] = dp[0][j - 1] && (s2[j - 1] == s3[j - 1]); } for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { dp[i][j] = dp[i - 1][j] && (s1[i - 1] == s3[i + j - 1]) || dp[i][j - 1] && (s2[j - 1] == s3[i + j - 1]); } } return dp[m][n]; }};
Small Case: 12ms
Large Case: 16ms
Time: O(n^2)
Space: O(n^2)
- LeetCode: Interleaving String
- LeetCode Interleaving String
- LeetCode: Interleaving String
- [Leetcode] Interleaving String
- [LeetCode] Interleaving String
- leetcode 68: Interleaving String
- [Leetcode] Interleaving String
- LeetCode - Interleaving String
- [LeetCode]Interleaving String
- LeetCode: Interleaving String
- Leetcode: Interleaving String
- [Leetcode]Interleaving String
- Leetcode: Interleaving String
- LeetCode:Interleaving String
- LeetCode-Interleaving String
- [leetcode] Interleaving String@DP
- LeetCode:Interleaving String
- LeetCode - Interleaving String
- Qt Class Wizard Example 看看看~
- ArcEngine+C# ——下拉框(ComboBox)颜色控件 (转)
- Linux下用Eclipse编译、安装、运行、调试PostgreSQL源码
- AE中IColor、IRGBColor和Win32 Color和.Net中Color相互转换
- VC 运行时库 /MD、/MDd 和 /MT、/MTd
- [LeetCode] Interleaving String
- Configure,Makefile.am, Makefile.in, Makefile文件之间
- leetcode 51: Generate Parentheses
- Analyzing billions of credit card transactions and serving low-latency insights in the cloud
- ibatis物理分页
- 寒假来了
- asp.net 自定义服务器控件属性 [Bindable(true)]...
- POJ 2014 K-th Number
- apache下绑定域名