Suppose I have the following function:
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;
}
Now supposedly if ransomNote
has an element which does not exist in the map, I understand by reading the documentation and the question:
What happens if I read a map's value where the key does not exist?
A new default key is constructed having the value ' '
. Now while referencing the key in second for loop, how is the value initialized to be zero?
How does the change in value corresponding to the key happen?
Is there any documentation for the same?