C++ Solution with basic String manipulations


  • 0
    G

    '''
    class Solution {
    public:
    bool canConstruct(string ransomNote, string magazine) {

        int len = 0;
        while(len < ransomNote.size())
        {
            int pos = magazine.find(ransomNote[len]);
            if (pos == std::string::npos)  // Can't find char
                return false;
            
            magazine.erase(pos, 1);    
            ++len;
        }
        return true;
    }
    

    };

    '''


Log in to reply
 

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