Did I underthink the problem? Accepted c++


  • 0
    F

    It seems this is the same basic idea most people used, but with far less overall work. The fact it was labeled medium makes me think I am missing some detail even though this passed....

    class Solution {
    public:
        bool isSubsequence(string s, string t) {
            int sPos = 0; 
            if(s == t) return true;
            for(auto c : t){
                if(c == s[sPos]) ++sPos;
                if(sPos == s.length()) return true;
            }
            return false;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.