天池 在线编程 能否转换

文章目录

1. 题目

给两个字符串 S 和 T, 判断 S 能不能通过删除一些字母(包括0个)变成 T.

样例1
输入: S = "lintcode" 和 T = "lint"
输出: true

样例2
输入: S = "lintcode" 和 T = "ide"
输出: true

样例3
输入: S = "adda" and T = "aad"
输出: false
解释: 无论如何,你都不能通过删除一个'd'"adda" 变成 "aad"

https://tianchi.aliyun.com/oj/286614371019772507/338469151696950135

2. 解题

class Solution {
public:
    /**
     * @param s: string S
     * @param t: string T
     * @return: whether S can convert to T
     */
    bool canConvert(string &s, string &t) {
        // Write your code here
        int n1 = s.size(), n2 = t.size();
        int i = 0, j = 0;
        while(i < n1 && j < n2)
        {
            if(s[i] == t[j])
                i++,j++;
            else
                i++;
        }
        return j==n2;
    }
};

8ms C++


我的CSDN博客地址 https://michael.blog.csdn.net/

长按或扫码关注我的公众号(Michael阿明),一起加油、一起学习进步!
Michael阿明

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Michael阿明

如果可以,请点赞留言支持我哦!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值