当前位置:网站首页>Won't you just stick to 62 days? Sum of words
Won't you just stick to 62 days? Sum of words
2022-07-29 04:16:00 【A little Ming】

class MapSum {
Map<String, Integer> map;
public MapSum() {
map = new HashMap<>();
}
public void insert(String key, int val) {
map.put(key,val);
}
public int sum(String prefix) {
int res = 0;
for (String s : map.keySet()) {
if (s.startsWith(prefix)) {
res += map.get(s);
}
}
return res;
}
}
author :LeetCode-Solution
link :https://leetcode.cn/problems/z1R5dt/solution/dan-ci-zhi-he-by-leetcode-solution-8vyo/
source : Power button (LeetCode)
The copyright belongs to the author . Commercial reprint please contact the author for authorization , Non-commercial reprint please indicate the source . 
class MapSum {
Map<String, Integer> map;
Map<String, Integer> prefixmap;
public MapSum() {
map = new HashMap<>();
prefixmap = new HashMap<>();
}
public void insert(String key, int val) {
int delta = val - map.getOrDefault(key, 0);
map.put(key, val);
for (int i = 1; i <= key.length(); ++i) {
String currprefix = key.substring(0, i);
prefixmap.put(currprefix, prefixmap.getOrDefault(currprefix, 0) + delta);
}
}
public int sum(String prefix) {
return prefixmap.getOrDefault(prefix, 0);
}
}
author :LeetCode-Solution
link :https://leetcode.cn/problems/z1R5dt/solution/dan-ci-zhi-he-by-leetcode-solution-8vyo/
source : Power button (LeetCode)
The copyright belongs to the author . Commercial reprint please contact the author for authorization , Non-commercial reprint please indicate the source .
边栏推荐
- There is a special cryptology language called asn.1
- 请问,在sql client中,执行insert into select from job时,如何单
- Target detection learning process
- opengauss预检查安装
- 12. Priority queue and inert queue
- Do you have a boss to help me check whether the parameter configuration of the Flink SQL connection Kafka authentication Kerberos is wrong
- 全屋WiFi方案:Mesh路由器组网和AC+AP
- kotlin的List,Map,Set等集合类不指定类型
- MySQL gets the maximum value record by field grouping
- Object detection: object_ Detection API +ssd target detection model
猜你喜欢
![[paper translation] vectornet: encoding HD maps and agent dynamics from vectorized representation](/img/4b/150689d5e4809ae66a4297915ecd0c.png)
[paper translation] vectornet: encoding HD maps and agent dynamics from vectorized representation

通过js来实现一元二次方程的效果,输入a,b,c系数后可计算出x1和x2的值

不会就坚持68天吧 狒狒吃香蕉

Deep learning training strategy -- warming up the learning rate

不会就坚持58天吧 实现前缀树

15.federation

2021 sist summer camp experience + record post of School of information, Shanghai University of science and technology

不会就坚持62天吧 单词之和

Compilation and linking

全屋WiFi方案:Mesh路由器组网和AC+AP
随机推荐
Blood cases caused by < meta charset=UTF-8> -- Analysis of common character codes
Machine vision Series 2: vs DLL debugging
Compilation and linking
[hands on deep learning] environment configuration (detailed records, starting from the installation of VMware virtual machine)
不会就坚持71天吧 链表排序
淘宝商品详情接口(商品详情页面数据接口)
How to write the filter conditions of data integration and what syntax to use? SQL syntax processing bizdate can not be
[Openstack] keystone,nova
The solution of porting stm32f103zet6 program to c8t6+c8t6 download program flash timeout
A little understanding of pointer, secondary pointer, wild pointer, pointer as function return value
不会就坚持60天吧 神奇的字典
The difference between dynamic, VaR and object in fluent
店铺排名问题,如何解决?
Pointer variables -printf%d and%p meaning
[kvm] create virtual machine from kickstart file
一个公司的面试笔记
The return value of the function is the attention of the pointer, the local variables inside the static limit sub function, and how the pointer to the array represents the array elements
Asp. Net MVC, how can the controller in the folder jump to the controller in the root directory?
LCA board
Change the value of the argument by address through malloc and pointer