File tree 1 file changed +18
-17
lines changed
scripts/algorithms/M/Map Sum Pairs
1 file changed +18
-17
lines changed Original file line number Diff line number Diff line change
1
+ // Runtime: 4 ms (Top 66.87%) | Memory: 7.9 MB (Top 80.77%)
1
2
class MapSum {
2
3
public:
3
- map<string,int >mp;
4
- MapSum () {
4
+ map<string,int >mp;
5
+ MapSum () {
5
6
6
- }
7
+ }
7
8
8
- void insert (string key, int val) {
9
- mp[key]=val;
10
- }
9
+ void insert (string key, int val) {
10
+ mp[key]=val;
11
+ }
11
12
12
- int sum (string prefix) {
13
- int count=0 ;
14
- for (auto i:mp){
15
- int j;
16
- for (j=0 ;j<i.first .size () && j<prefix.size ();j++){
17
- if (i.first [j]!=prefix[j])break ;
18
- }
19
- if (j==prefix.size ())count+=i.second ;
20
- }
21
- return count;
22
- }
13
+ int sum (string prefix) {
14
+ int count=0 ;
15
+ for (auto i:mp){
16
+ int j;
17
+ for (j=0 ;j<i.first .size () && j<prefix.size ();j++){
18
+ if (i.first [j]!=prefix[j])break ;
19
+ }
20
+ if (j==prefix.size ())count+=i.second ;
21
+ }
22
+ return count;
23
+ }
23
24
};
You can’t perform that action at this time.
0 commit comments