当前位置:网站首页>不会就坚持58天吧 实现前缀树
不会就坚持58天吧 实现前缀树
2022-07-29 04:13:00 【一只小小明】

class Trie {
private Trie[] children;
private boolean isEnd;
public Trie() {
children = new Trie[26];
isEnd = false;
}
public void insert(String word) {
Trie node = this;
for (int i = 0; i < word.length(); i++) {
char ch = word.charAt(i);
int index = ch - 'a';
if (node.children[index] == null) {
node.children[index] = new Trie();
}
node = node.children[index];
}
node.isEnd = true;
}
public boolean search(String word) {
Trie node = searchPrefix(word);
return node != null && node.isEnd;
}
public boolean startsWith(String prefix) {
return searchPrefix(prefix) != null;
}
private Trie searchPrefix(String prefix) {
Trie node = this;
for (int i = 0; i < prefix.length(); i++) {
char ch = prefix.charAt(i);
int index = ch - 'a';
if (node.children[index] == null) {
return null;
}
node = node.children[index];
}
return node;
}
}边栏推荐
- C语言:浅谈各种复杂的声明
- "Weilai Cup" 2022 Niuke summer multi school training camp 2H
- Taobao product details interface (product details page data interface)
- 路由 知识
- [kvm] common commands
- Locally call tensorboard and Jupiter notebook on the server (using mobaxterm)
- 请问为什么我进行mysql数据update时,kafka中采集到的是先删除原纪录(op d)再新增新
- Do you have a boss to help me check whether the parameter configuration of the Flink SQL connection Kafka authentication Kerberos is wrong
- HCIP BGP
- First knowledge of C language (3)
猜你喜欢

初识C语言(3)

2021 sist summer camp experience + record post of School of information, Shanghai University of science and technology

不会就坚持68天吧 狒狒吃香蕉

Nacos registry

The solution of porting stm32f103zet6 program to c8t6+c8t6 download program flash timeout

C语言实现三子棋游戏(详解)

HCIP BGP

Svg -- loading animation

不会就坚持62天吧 单词之和

Problems encountered in vscode connection SSH
随机推荐
opengauss预检查安装
请问为什么我进行mysql数据update时,kafka中采集到的是先删除原纪录(op d)再新增新
(.*?) regular expression
大佬们flink的JDBC SQL Connector现在不支持所有的数据库吗,例如vertica?
Note: restframe work records many to one tables, how to serialize in that table (reverse query)
路由 知识
Applet: Area scrolling, pull-down refresh, pull-up load more
MySQL Part 3
Fuzzy query of SQL
从淘宝,天猫,1688,微店,京东,苏宁,淘特等其他平台一键复制商品到拼多多平台(批量上传宝贝详情接口教程)
Function pointer and callback function
View partition table format
The solution of porting stm32f103zet6 program to c8t6+c8t6 download program flash timeout
Why do I delete the original record (OP d) and then add a new one in Kafka when I update MySQL data
[paper translation] vectornet: encoding HD maps and agent dynamics from vectorized representation
Class starts! See how smardaten decomposes complex business scenarios
Routing knowledge
Design of environment detection system based on STM32 and Alibaba cloud
数据源是SQL server ,我要配置日期字段 updateDate 最后两天日期的增量数据,做增
MySQL gets the maximum value record by field grouping