当前位置:网站首页>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 .
边栏推荐
- Shielding ODBC load balancing mode in gbase 8A special scenarios?
- Implementation of jump connection of RESNET (pytorch)
- Pat a1069/b1019 the black hole of numbers
- Change the value of the argument by address through malloc and pointer
- C语言:枚举知识点总结
- C语言:联合体知识点总结
- How to solve the problem of store ranking?
- 小程序:区域滚动、下拉刷新、上拉加载更多
- Beginner: array & String
- (.*?) regular expression
猜你喜欢

UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0x90 in position 614: ordinal not in range(128)

The principle of inverse Fourier transform (IFFT) in signal processing

9. Delay queue

信号处理中的反傅里叶变换(IFFT)原理

顺序表和链表

Lua语言(stm32+2G/4G模块)和C语言(stm32+esp8266)从字符串中提取相关数据的方法-整理

Const char* and char*, string constants

14.haproxy+keepalived负载均衡和高可用

Is the array name a pointer

Compilation and linking
随机推荐
Blood cases caused by < meta charset=UTF-8> -- Analysis of common character codes
The pit I walked through: the first ad Sketchpad
请问为什么我进行mysql数据update时,kafka中采集到的是先删除原纪录(op d)再新增新
数据源是SQL server ,我要配置日期字段 updateDate 最后两天日期的增量数据,做增
一个公司的面试笔记
Jenkins 参数化构建中 各参数介绍与示例
Why are there so many unknowns when opengauss starts?
Pointer of pointer???...
[kvm] install KVM
Locker 2022.1.1
Machine vision Series 1: Visual Studio 2019 dynamic link library DLL establishment
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)
Whole house WiFi solution: mesh router networking and ac+ap
15.federation
What the hell is this error? It doesn't affect the execution result, but it always reports errors when executing SQL... Connecting maxcomputer uses
Database SQL statement realizes function query of data decomposition
C language - character array - string array - '\0' -sizeof-strlen() -printf()
10. Fallback message
Can you really write restful API?
不会就坚持63天吧 最大的异或