class MapSum {
public:
unordered_map<string , int>hash;
/** Initialize your data structure here. */
MapSum() {
}
void insert(string key, int val) {
hash[key]=val;
}
int sum(string prefix) {
int sum=0;
for(auto n:hash)
{
if(prefix==n.first.substr(0,prefix.size()))
sum+=n.second;
}
return sum;
}
};
public:
unordered_map<string , int>hash;
/** Initialize your data structure here. */
MapSum() {
}
void insert(string key, int val) {
hash[key]=val;
}
int sum(string prefix) {
int sum=0;
for(auto n:hash)
{
if(prefix==n.first.substr(0,prefix.size()))
sum+=n.second;
}
return sum;
}
};