c++ greedy solution use queue


  • 1
    A
    class Solution {
    public:
        bool isSubsequence(string s, string t) {
            if(s.length() == 0) return true;
            queue<char> q;
            for(char c : s) q.push(c);
            for(int i=0;!q.empty() && i<t.length();i++){
                if(t[i] == q.front()){
                    q.pop();
                }
            }
            return q.empty();
        }
    };
    

  • 0
    R

    Brilliant! Smart solution!


Log in to reply
 

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