当前位置:网站首页>392. Judgement subsequence
392. Judgement subsequence
2022-07-04 14:01:00 【anieoo】
Original link :392. Judging subsequences
solution:
Dynamic programming :
State means :dp[i][j]: Express s Before i Are the letters yes t Before j Subsequence of letters of
State calculation : If s[i] == t[j] be ,dp[i][j] = dp[i - 1][j - 1], otherwise dp[i][j] = dp[i][j - 1]
class Solution {
public:
bool isSubsequence(string s, string t) {
int m = s.size(),n = t.size();
if(m > n) return false; //m Longer than n It must not be a subsequence
vector<vector<bool>> dp(m + 1, vector<bool> (n + 1, false));
//dp[i][j]: Express s Before i Are the letters yes t Before j Subsequence of letters of
for(int i = 0;i <= n;i++) dp[0][i] = true;
for(int i = 1;i <= m;i++) {
for(int j = 1;j <= n;j++) {
if(s[i - 1] == t[j - 1]) {
dp[i][j] = dp[i - 1][j - 1];
} else {
dp[i][j] = dp[i][j - 1];
}
}
}
return dp[m][n];
}
};Double pointer , Only s[j] == t[i], The pointer j To move backwards .
class Solution {
public:
bool isSubsequence(string s, string t) {
int m = s.size(),n = t.size();
if(!m) return true;
if(m > n) return false;
for(int i = 0,j = 0;i < n;i++) {
if(s[j] == t[i]) j++;
if(j == m) return true;
}
return false;
}
};边栏推荐
- E-week finance | Q1 the number of active people in the insurance industry was 86.8867 million, and the licenses of 19 Payment institutions were cancelled
- 嵌入式编程中五个必探的“潜在错误”
- Go 语言入门很简单:Go 实现凯撒密码
- 【Antd】Antd 如何在 Form.Item 中有 Input.Gourp 时获取 Input.Gourp 的每一个 Input 的value
- C language staff management system
- Huahao Zhongtian sprint Technology Innovation Board: perte annuelle de 280 millions de RMB, projet de collecte de fonds de 1,5 milliard de Beida Pharmaceutical est actionnaire
- 分布式BASE理论
- 逆向调试入门-PE结构-资源表07/07
- OpenHarmony应用开发之如何创建DAYU200预览器
- C array supplement
猜你喜欢

.Net之延迟队列

锐成芯微冲刺科创板:年营收3.67亿拟募资13亿 大唐电信是股东

HAProxy高可用解决方案

Oracle was named the champion of Digital Innovation Award by Ventana research

Node の MongoDB安装

2022危险化学品经营单位主要负责人练习题及模拟考试

Commvault 和 Oracle 合作,在 Oracle 云上提供 Metallic数据管理即服务

Flet tutorial 03 basic introduction to filledbutton (tutorial includes source code) (tutorial includes source code)

面试拆解:系统上线后Cpu使用率飙升如何排查?

Install Trinity and solve error reporting
随机推荐
Node の MongoDB安装
易周金融 | Q1保险行业活跃人数8688.67万人 19家支付机构牌照被注销
读取 Excel 表数据
Oracle was named the champion of Digital Innovation Award by Ventana research
C语言小型商品管理系统
C语言宿舍管理查询软件
The only core indicator of high-quality software architecture
担心“断气” 德国正修改《能源安全法》
动画与过渡效果
2022年山东省安全员C证考试题库及在线模拟考试
2022年起重机械指挥考试模拟100题模拟考试平台操作
MongoDB常用28条查询语句(转)
Oracle 被 Ventana Research 评为数字创新奖总冠军
[C question set] of VII
C语言课程设计题
免费、好用、强大的轻量级笔记软件评测:Drafts、Apple 备忘录、Flomo、Keep、FlowUs、Agenda、SideNote、Workflowy
C basic supplement
Introduction to XML II
Getting started with the go language is simple: go implements the Caesar password
DGraph: 大规模动态图数据集