cpp 26ms simple find solution


  • 0
    Z
    #include <algorithm>
    class Solution {
    public:
        bool canConstruct(string ransomNote, string magazine) {
            for (auto c: ransomNote) {
                auto it = std::find(magazine.begin(), magazine.end(), c);
                if (it != magazine.end()) {
                    magazine.erase(it);
                } else {
                    return false;
                }
            }
            return true;
        }
    };
    

Log in to reply
 

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