forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_677.java
36 lines (28 loc) · 810 Bytes
/
_677.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package com.fishercoder.solutions;
import java.util.HashMap;
import java.util.Map;
public class _677 {
public static class Solution1 {
public static class MapSum {
Map<String, Integer> map;
/**
* Initialize your data structure here.
*/
public MapSum() {
map = new HashMap<>();
}
public void insert(String key, int val) {
map.put(key, val);
}
public int sum(String prefix) {
int sum = 0;
for (String key : map.keySet()) {
if (key.startsWith(prefix)) {
sum += map.get(key);
}
}
return sum;
}
}
}
}