We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Something that is missing in the description of the map container: when using m[key] as a left value, if key is not in the map, it is inserted using the default constructor for the value (second member of the pair).
Consider a map like this:
map<string, int> m;
Thus, if you write:
m[key] += v
And key is not present, it behave as:
m.insert(make_pair(key, v))
or:
m[key] = v
Since the default value for an int is 0. Which greatly simplifies the first operation in the exercise.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Maps-STL
You are viewing a single comment's thread. Return to all comments →
Something that is missing in the description of the map container: when using m[key] as a left value, if key is not in the map, it is inserted using the default constructor for the value (second member of the pair).
Consider a map like this:
Thus, if you write:
And key is not present, it behave as:
or:
Since the default value for an int is 0. Which greatly simplifies the first operation in the exercise.