7 Star 34 Fork 23

空無一悟/algorithms

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
MapSum.java 985 Bytes
一键复制 编辑 原始数据 按行查看 历史
空無一悟 提交于 2021-09-22 23:47 +08:00 . init
/***********************************************************
* @Description : LeetCode题号为677,当Trie中单词加入权重后,计算指定单词的权重值
* @author : 梁山广(Laing Shan Guang)
* @date : 2018/5/19 22:16
* @email : liangshanguang2@gmail.com
***********************************************************/
package Chapter10Trie.Section6Leetcode677MapSum;
public class MapSum {
private TrieWeighted trieWeighted;
public MapSum() {
trieWeighted = new TrieWeighted();
}
public void insert(String key, int val) {
trieWeighted.add(key, val);
}
public int sum(String prefix) {
return trieWeighted.getWeight(prefix);
}
public static void main(String[] args) {
MapSum mapSum = new MapSum();
mapSum.insert("apple", 3);
System.out.println(mapSum.sum("ap"));
mapSum.insert("app", 2);
System.out.println(mapSum.sum("ap"));
}
}
/**
* 3
* 5
*/
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/lsgwr/algorithms.git
git@gitee.com:lsgwr/algorithms.git
lsgwr
algorithms
algorithms
master

搜索帮助