当前位置:网站首页>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 .
边栏推荐
- Target detection learning process
- 为什么opengauss启动的时候这么多的unknown?
- Machine vision series 3:vs2019 opencv environment configuration
- 不会就坚持66天吧 权重生成随机数
- Function pointer and callback function
- [untitled]
- 对一个元素使用多种变形的方法
- Pix2.4.8 from start to installation (2021.4.4)
- Fu Yingna: Yuan universe is the new generation of Internet!
- [k210 stepping pit] pytorch model is converted to kmodel and used on dock. (ultimately not achieved)
猜你喜欢
Problems encountered in vscode connection SSH
编译与链接
How to solve the problem of store ranking?
小程序:区域滚动、下拉刷新、上拉加载更多
Install the laser of ROS_ scan_ Problems encountered in match library (I)
When array is used as a function parameter, it is better to use the array size as a function parameter
伏英娜:元宇宙就是新一代互联网!
11.备份交换机
Blood cases caused by < meta charset=UTF-8> -- Analysis of common character codes
Record of problems encountered in ROS learning
随机推荐
LCA 板子
顺序表和链表
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)
请问,在sql client中,执行insert into select from job时,如何单
小程序:区域滚动、下拉刷新、上拉加载更多
Two forms of softmax cross entropy + numpy implementation
Solution: module 'xlrd' has no attribute 'open_ Error reporting of workbook '
There is a special cryptology language called asn.1
SVG--loading动画
Beginner: array & String
[k210 stepping pit] pytorch model is converted to kmodel and used on dock. (ultimately not achieved)
15.federation
不会就坚持58天吧 实现前缀树
[untitled]
[hands on deep learning] environment configuration (detailed records, starting from the installation of VMware virtual machine)
BIO、NIO、AIO的区别和原理
Pointer constant and constant pointer
A little understanding of pointer, secondary pointer, wild pointer, pointer as function return value
Multi card training in pytorch
Code or script to speed up the video playback of video websites