当前位置:网站首页>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];
}
};
边栏推荐
猜你喜欢

详解CAN总线:常用CAN连接器的使用方法

C语言实现-华为太空人手表

Error ER_NOT_SUPPORTED_AUTH_MODE Client does not support authentication protocol requested by serv

舍不得花钱买1stOpt,不妨试试这款免费的拟合优化神器【openLU】

七夕送礼,心愿直抵!

小猫爪:AWR294x学习笔记02-AWR294x之DPM&IPC

DropBlock: Regularization method and reproduction code for convolutional layers

CAN协议详解-01

两日总结七

数据特征预处理——缺失值的查看方式及处理
随机推荐
两日总结五
MotionLayout的使用
Sql优化总结!详细!(2021最新面试必问)
一天学会JDBC04:ResultSet的用法
花了近70美元入手的学生版MATLAB体验到底如何?
The school to apply for link
用手机也能轻松玩转MATLAB编程
NelSon:一款新的适配matlab编程语法的编程工具
The national vocational skills contest competition of network security emergency response
两日总结六
90多款matlab工具箱打包放送
SQL如何从字符串截取指定字符(LEFT、MID、RIGHT三大函数)
LLVM编译技术应用分析
【论文笔记】—低照度图像增强—Supervised—RetinexNet—2018-BMVC
错误记录:TypeError: object() takes no parameters
MySQL配置文件配置
【学习笔记】AGC036
ThreadLocal内存泄漏问题讲解
反序列化字符逃逸漏洞之
Verilog“七宗罪”
