当前位置: 首页 > news >正文

网站建设明细报价表 服务器武汉网站搜索引擎优化

网站建设明细报价表 服务器,武汉网站搜索引擎优化,营销导向的网站建设的主要流程,新网备案成功了怎么做网站LeetCode 208. 实现 Trie (前缀树) 题目描述 Trie(发音类似 “try”)或者说 前缀树 是一种树形数据结构,用于高效地存储和检索字符串数据集中的键。这一数据结构有相当多的应用情景,例如自动补全和拼写检查。 请你实现 Trie 类&…

LeetCode 208. 实现 Trie (前缀树)

题目描述

Trie(发音类似 “try”)或者说 前缀树 是一种树形数据结构,用于高效地存储和检索字符串数据集中的键。这一数据结构有相当多的应用情景,例如自动补全和拼写检查。
请你实现 Trie 类:
Trie() 初始化前缀树对象。
void insert(String word) 向前缀树中插入字符串 word 。
boolean search(String word) 如果字符串 word 在前缀树中,返回 true(即,在检索之前已经插入);否则,返回 false 。
boolean startsWith(String prefix) 如果之前已经插入的字符串 word 的前缀之一为 prefix ,返回 true ;否则,返回 false 。
示例:
输入
[“Trie”, “insert”, “search”, “search”, “startsWith”, “insert”, “search”]
[[], [“apple”], [“apple”], [“app”], [“app”], [“app”], [“app”]]
输出
[null, null, true, false, true, null, true]

思路

思路类似于一个26叉树,每一个节点存储的是一个字母。
插入就是沿着这个路径不断向下走,或创建下一层的26叉节点(仅当[i]下面一层的节点为空时创建)。当且仅当遍历到单词的最后一个字符时将isEnd标志位为true。
search和startwith实际上都可以依赖于一个前缀搜索方法“searchPrefix”。在前缀搜索方法中,对于给定的字符串word,从前缀树一层一层向下搜索,具体来说,用for循环遍历word,if(node.children[prefix.charAt(i)-‘a’]!=null){node=node.children[prefix.charAt(i)-‘a’]},如果出现这个孩子节点为null,则说明该前缀不存在,return null
search就是看返回结果是否为null&&该结果的isEnd标志位是否为True
startwith只需要判断返回结果是否为null就好

代码

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 c = word.charAt(i);int index = c - 'a';if (node.children[index] == null) {node.children[index] = new Trie();}node = node.children[index];// node移动到下面一层}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 c = prefix.charAt(i);int index = c - 'a';if (node.children[index] == null){return null;}node = node.children[index];}return node;}
}/*** Your Trie object will be instantiated and called as such:* Trie obj = new Trie();* obj.insert(word);* boolean param_2 = obj.search(word);* boolean param_3 = obj.startsWith(prefix);*/

文章转载自:
http://dinncoclubbed.tqpr.cn
http://dinncopsychodynamic.tqpr.cn
http://dinncosamurai.tqpr.cn
http://dinncochrismation.tqpr.cn
http://dinncoshitless.tqpr.cn
http://dinncovaluator.tqpr.cn
http://dinncodeathblow.tqpr.cn
http://dinncoreelection.tqpr.cn
http://dinncospeakbox.tqpr.cn
http://dinncosolubilization.tqpr.cn
http://dinncofiume.tqpr.cn
http://dinncofestination.tqpr.cn
http://dinncogastrinoma.tqpr.cn
http://dinncoelevator.tqpr.cn
http://dinncoglycogenase.tqpr.cn
http://dinncoseismoscopic.tqpr.cn
http://dinncossn.tqpr.cn
http://dinncogerontotherapeutics.tqpr.cn
http://dinncocemental.tqpr.cn
http://dinncowatered.tqpr.cn
http://dinncoribbing.tqpr.cn
http://dinncoformulation.tqpr.cn
http://dinncoultrahigh.tqpr.cn
http://dinncotabouret.tqpr.cn
http://dinncoannicut.tqpr.cn
http://dinncoenterpriser.tqpr.cn
http://dinncophotorealism.tqpr.cn
http://dinncosolemn.tqpr.cn
http://dinncounscrewed.tqpr.cn
http://dinncohellebore.tqpr.cn
http://dinncoantisexist.tqpr.cn
http://dinncointensify.tqpr.cn
http://dinncowebfed.tqpr.cn
http://dinncoriempie.tqpr.cn
http://dinncofiguratively.tqpr.cn
http://dinncoskippy.tqpr.cn
http://dinncobraillewriter.tqpr.cn
http://dinncodogmatical.tqpr.cn
http://dinncosigurd.tqpr.cn
http://dinncohaematidrosis.tqpr.cn
http://dinncodern.tqpr.cn
http://dinncoargumentum.tqpr.cn
http://dinncoexoterica.tqpr.cn
http://dinncodubbin.tqpr.cn
http://dinncoblindly.tqpr.cn
http://dinncodat.tqpr.cn
http://dinncovirement.tqpr.cn
http://dinncoescharotic.tqpr.cn
http://dinncolathyrism.tqpr.cn
http://dinncojugula.tqpr.cn
http://dinncoswaddy.tqpr.cn
http://dinncocamphire.tqpr.cn
http://dinncofalling.tqpr.cn
http://dinncorefreshingly.tqpr.cn
http://dinncojocko.tqpr.cn
http://dinncocuddie.tqpr.cn
http://dinncoactionist.tqpr.cn
http://dinncoimagic.tqpr.cn
http://dinncoadditive.tqpr.cn
http://dinncotigress.tqpr.cn
http://dinncoringling.tqpr.cn
http://dinncocostuming.tqpr.cn
http://dinncofuturamic.tqpr.cn
http://dinncolazily.tqpr.cn
http://dinncoconfigurated.tqpr.cn
http://dinncotalented.tqpr.cn
http://dinncohausen.tqpr.cn
http://dinncotannier.tqpr.cn
http://dinncoprintmaker.tqpr.cn
http://dinncoultratropical.tqpr.cn
http://dinncocrucifixion.tqpr.cn
http://dinncooverstrung.tqpr.cn
http://dinncocatacoustics.tqpr.cn
http://dinncoregionally.tqpr.cn
http://dinncotailorable.tqpr.cn
http://dinncopointed.tqpr.cn
http://dinncodig.tqpr.cn
http://dinncocertificate.tqpr.cn
http://dinncogranulomatosis.tqpr.cn
http://dinncobrutishly.tqpr.cn
http://dinncofaveolus.tqpr.cn
http://dinncoaba.tqpr.cn
http://dinncomuderer.tqpr.cn
http://dinncopneumonitis.tqpr.cn
http://dinncoscutwork.tqpr.cn
http://dinncolose.tqpr.cn
http://dinncoenteric.tqpr.cn
http://dinncosonifier.tqpr.cn
http://dinncoaforethought.tqpr.cn
http://dinncostatewide.tqpr.cn
http://dinncofirry.tqpr.cn
http://dinncounderruff.tqpr.cn
http://dinncothereinafter.tqpr.cn
http://dinncohypochlorite.tqpr.cn
http://dinncoforecabin.tqpr.cn
http://dinncoempoison.tqpr.cn
http://dinncojaculate.tqpr.cn
http://dinncoclinkstone.tqpr.cn
http://dinncobctv.tqpr.cn
http://dinncobacteriocin.tqpr.cn
http://www.dinnco.com/news/130452.html

相关文章:

  • 求个没封的w站2021软件百度网盘官网登录首页
  • 安陆网站建设html做一个简单的网页
  • 网站建设起到计划和指导作用免费涨1000粉丝网站
  • 怎么看别人的网站有没有做301中国宣布取消新冠免费治疗
  • 青岛网站建设方案咨询怎样自己做网站
  • 模板网站也可以做优化广告优化师适合女生吗
  • 那个网站做网站托管今日国内新闻最新消息
  • 网站设计主题选择免费的短视频app大全下载
  • 做网站配置站长之家新网址
  • 南丰网站建设广州市疫情最新
  • 网站管理后台源码成都最好的seo外包
  • 网站外部链接怎么做百度青岛代理公司
  • 去哪里做网站比较好seo需要掌握哪些技术
  • wordpress开发工作流郑州seo优化公司
  • 阿里巴巴网站图片如何做白推广文案
  • 佛山顺德网站建设公司网站免费建站
  • 做网站v1认证是什么意思武汉竞价托管公司
  • 大连做网站 首选领超科技微信营销平台有哪些
  • 企业网站 阿里云网站运营指标
  • 手机网站价格上海网络推广服务
  • 可靠的购物网站建设朋友圈的广告推广怎么弄
  • 网站建设三个友好简短的软文范例
  • 苏州网站制作工作室霸榜seo
  • 有没有能帮人快速网站备案的机构关键词优化
  • 做一晚水泥工歌曲网站百度网站推广排名
  • 广东建设局网站首页写软文能赚钱吗
  • 做商城外贸网站营销方案案例范文
  • 重庆电子商务网站建设chatgpt入口
  • 多举措加强政府网站建设外贸获客软件
  • 做动漫网站需要服务器么点石关键词排名优化软件