当前位置:网站首页>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];
}
};
边栏推荐
猜你喜欢
随机推荐
likeshop外卖点餐系统开源啦100%开源无加密
分布式计算实验1 负载均衡
matlab让我的旧手机起死回生
unity 循环选择器
The national vocational skills contest competition of network security emergency response
powershell和cmd对比
MotionLayout的使用
MySQL大总结
两日总结四
最强分布式锁工具:Redisson
有人试过用NPGsql驱动连接openGauss开发应用的吗?
带你了解一下PHP搭建的电商商城系统
JVM调优实践
Redis非关系型数据库
SystemVerilog-条件(三元)运算符
解决:Hbuilder工具点击发行打包,一直报尚未完成社区身份验证,请点击链接xxxxx,项目xxx发布H5失败的错误。
经典新诗九首
New Questions in Module B of Secondary Vocational Network Security Competition
Verilog“七宗罪”
MySQL基础(DDL、DML、DQL)


![玩转TypeScript对象、对象作为参数进行函数传递、接口和内置对象[无敌态]](/img/23/3405b488d11a4700a9b47758214574.png)






