2816. 判断子序列

题目链接:

自己的做法:

cpp 复制代码
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 10;
int a[N], b[N];
int main()
{
    int n, m;
    bool flag = true;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    for (int i = 0; i < m; i++) scanf("%d", &b[i]);
    int j = 0, i = 0;
        while (j < m && i < n) {
            if (a[i] == b[j]) i++, j++, flag = true;
            else j++, flag = false;
        }
    if (i == n && flag) cout << "Yes";
    else cout << "No";
    return 0;
}

推荐解法:

相关推荐
ASKED_20191 天前
从排序到生成:腾讯广告算法大赛 2025 baseline解读
人工智能·算法
田梓燊1 天前
leetcode 160
算法·leetcode·职场和发展
_深海凉_1 天前
LeetCode热题100-颜色分类
python·算法·leetcode
网安INF1 天前
数据结构第三章:栈、队列和数组
数据结构
hetao17338371 天前
2026-04-09~12 hetao1733837 的刷题记录
c++·算法
6Hzlia1 天前
【Hot 100 刷题计划】 LeetCode 136. 只出现一次的数字 | C++ 哈希表&异或基础解法
c++·算法·leetcode
MWWZ1 天前
最近的一些软件更新
opencv·算法·计算机视觉
CoovallyAIHub1 天前
视频理解新范式:Agent不再被动看视频,LensWalk让它自己决定看哪里
算法·架构·github
汉克老师1 天前
GESP2024年6月认证C++三级( 第二部分判断题(1-10))
c++·数组·位运算·补码·gesp三级·gesp3级
CoovallyAIHub1 天前
斯坦福丨AirVLA:将地面机械臂模型迁移至无人机实现空中抓取,成功率从23%提升至50%
算法·架构·github