当前位置:网站首页>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 .
边栏推荐
- [k210 stepping pit] pytorch model is converted to kmodel and used on dock. (ultimately not achieved)
- Why are there so many unknowns when opengauss starts?
- 对一个元素使用多种变形的方法
- Installation and use of stm32cubemx (5.3.0)
- 数据源是SQL server ,我要配置日期字段 updateDate 最后两天日期的增量数据,做增
- 索引的最左前缀原理
- C language: getchar () and cache
- "Weilai Cup" 2022 Niuke summer multi school training camp 2H
- 不会就坚持69天吧 合并区间
- The difference between dynamic, VaR and object in fluent
猜你喜欢

Mmdetection preliminary use

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

Whole house WiFi solution: mesh router networking and ac+ap

Lua language (stm32+2g/4g module) and C language (stm32+esp8266) methods of extracting relevant data from strings - collation

12.优先级队列和惰性队列

Record of problems encountered in ROS learning

Design of environment detection system based on STM32 and Alibaba cloud
![[Openstack] keystone,nova](/img/de/70b654a29a813c8fe828c4018bd4e7.png)
[Openstack] keystone,nova

不会就坚持69天吧 合并区间

UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0x90 in position 614: ordinal not in range(128)
随机推荐
Leftmost prefix principle of index
[hands on deep learning] environment configuration (detailed records, starting from the installation of VMware virtual machine)
小程序:区域滚动、下拉刷新、上拉加载更多
There is a special cryptology language called asn.1
有一种密码学专用语言叫做ASN.1
淘宝商品详情接口(商品详情页面数据接口)
rman不标记过期备份
不会就坚持68天吧 狒狒吃香蕉
[kvm] create virtual machine from kickstart file
开课!看smardaten如何分解复杂业务场景
10. Fallback message
不会就坚持65天吧 只出现一次的数字
Compilation and linking
数据集成这个地方的过滤条件该咋写,用的啥语法?sql语法处理bizdate可以不
[k210 stepping pit] pytorch model is converted to kmodel and used on dock. (ultimately not achieved)
Pat a1069/b1019 the black hole of numbers
SQL time fuzzy query datediff() function
Implementation of jump connection of RESNET (pytorch)
C语言:typedef知识点总结
MPU6050