The complexity is O(N), N is the length of magazine.

```
class Solution {
public:
bool canConstruct(string ransomNote, string magazine) {
unordered_map<char, int> map(26);
for (int i = 0; i < magazine.size(); ++i)
++map[magazine[i]];
for (int j = 0; j < ransomNote.size(); ++j)
if (--map[ransomNote[j]] < 0)
return false;
return true;
}
};
```

Or you can use a vector with size 26 instead of an unordered_map.

```
class Solution {
public:
bool canConstruct(string ransomNote, string magazine) {
vector<int> vec(26, 0);
for (int i = 0; i < magazine.size(); ++i)
++vec[magazine[i] - 'a'];
for (int j = 0; j < ransomNote.size(); ++j)
if (--vec[ransomNote[j] - 'a'] < 0)
return false;
return true;
}
};
```

I remember that there are two variations of this question, perhaps they will come in the next few days :)

- If you can only pick letters from the magazine in order.
- If the magazine is double sided.