Simple C++ Solution Counting Letters, O(n+m), 22ms

  • -1
    class Solution {
        bool canConstruct(string ransomNote, string magazine) {
            vector<int> cnt(128);
            for (char c: magazine) ++cnt[c];
            for (char c: ransomNote) {
                if (cnt[c] <= 0) return false;
            return true;

Log in to reply

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