当前位置:网站首页>LeetCode 97. 交错字符串
LeetCode 97. 交错字符串
2022-08-04 06:42:00 【HumbleFool】
const int N = 110;
class Solution {
public:
bool f[N][N] = {
false}; // 是 s1 前 i 个字符和 s2 前 j 个字符能够组成 s3 前 i+j
bool isInterleave(string s1, string s2, string s3) {
int n = s1.size(), m = s2.size();
if(n + m != s3.size()) return false;
f[0][0] = true;
for(int i = 1; i <= n; i ++)
if(s1[i - 1] != s3[i - 1])
break;
else f[i][0] = true;
for(int i = 1; i <= m; i ++)
if(s2[i - 1] != s3[i - 1])
break;
else f[0][i] = true;
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= m; j ++)
{
f[i][j] = (s1[i - 1] == s3[i + j - 1] && f[i - 1][j]) || (s2[j - 1] == s3[i + j - 1] && f[i][j - 1]); //是当前字符是s1, 或者s2
}
return f[n][m];
}
};
边栏推荐
猜你喜欢
随机推荐
10个程序员可以接私活的平台和一些建议,赚麻...
mysql锁机制
IDEA中创建编写JSP
matlab封闭曲线拟合 (针对一些列离散点)
JVM工具之 JPS
在线问题反馈模块实战(十八):实现excel台账文件记录批量导入功能
ThreadLocal内存泄漏问题讲解
经典新诗九首
缓存穿透、击穿、雪崩
matlab科研绘图模板,直接奉上源代码!
data:image/jpg; base64 format data is converted to image
Provide 和 Inject 的用法
中职网络安全竞赛C模块MS17-010批量扫描
Error occurred while trying to proxy request项目突然起不来了
函数柯里化详解
MATLAB版量化交易技术分析工具TA-Lib【不付费也可获取,不要被付费吓跑】
将回调函数转为Flow
使用腾讯云发送短信 ---- 手把手教你搞定所有步骤
powershell和cmd对比
系统流量预估、架构设计方案





![[想要访问若依后台]若依框架报错401请求访问:error认证失败,无法访问系统资源](/img/aa/701fef9d8d7eaf25082e1289799b77.png)




