当前位置:网站首页>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 .
边栏推荐
- %s. %c, character constant, string constant, const char*, pointer array, string array summary
- How to solve the problem of store ranking?
- How to write the filter conditions of data integration and what syntax to use? SQL syntax processing bizdate can not be
- Asp. Net MVC, how can the controller in the folder jump to the controller in the root directory?
- Database SQL statement realizes function query of data decomposition
- Change the value of the argument by address through malloc and pointer
- flink-sql 如何设置 sql执行超时时间
- Function pointer and callback function
- [material delivery UAV] record (ROS + Px4 + yolov5 + esp8266 + steering gear)
- Taobao product details interface (product details page data interface)
猜你喜欢
随机推荐
[kvm] common commands
[hands on deep learning] environment configuration (detailed records, starting from the installation of VMware virtual machine)
Copy products with one click from Taobao, tmall, 1688, wechat, jd.com, Suning, taote and other platforms to pinduoduo platform (batch upload baby details Interface tutorial)
[k210 stepping pit] pytorch model is converted to kmodel and used on dock. (ultimately not achieved)
数据库SQL语句实现数据分解的函数查询
The solution of porting stm32f103zet6 program to c8t6+c8t6 download program flash timeout
Const char* and char*, string constants
Pat a1069/b1019 the black hole of numbers
Change the value of the argument by address through malloc and pointer
opengauss预检查安装
Methods of using multiple deformations on an element
LCA board
Pointer variables -printf%d and%p meaning
Machine vision series 3:vs2019 opencv environment configuration
[material delivery UAV] record (ROS + Px4 + yolov5 + esp8266 + steering gear)
There is a special cryptology language called asn.1
小程序:区域滚动、下拉刷新、上拉加载更多
不会就坚持64天吧 查找插入位置
优炫数据库有办法查到主集群每天传给备集群的日志量吗?
10.回退消息









