题解 | #特工的密码#

特工的密码

https://www.nowcoder.com/practice/bcdfed09de534aea92b24c73699dba5c

题目考察的知识点:字符串的遍历

题目解答方法的文字分析:用s中的元素遍历t中的元素即可。

本题解析所用的编程语言:c++

class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param s string字符串 
     * @param t string字符串 
     * @return bool布尔型
     */
    bool isSubsequence(string s, string t)
    {
        // write code here
        int i = 0, j = 0;
        for (i = 0, j = 0; i < t.size(); ++i)
        {
            if (s[j] == t[i])
                ++j;
        }
        if (j == s.size())
            return true;
        return false;
    }
};

全部评论

相关推荐

评论
2
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务