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

手机网站开发方式网络营销的特征

手机网站开发方式,网络营销的特征,网站后台用java怎么做,wordpress 分块首页字典树(前缀树) 208. 实现 Trie (前缀树)题目描述示例知识补充官解代码 211. 添加与搜索单词 - 数据结构设计题目描述示例思路Java代码 208. 实现 Trie (前缀树) 力扣链接:208. 实现 Trie (前缀树) 题目描述 示例 知识补充 插入字符串 我…

字典树(前缀树)

  • 208. 实现 Trie (前缀树)
    • 题目描述
    • 示例
    • 知识补充
    • 官解代码
  • 211. 添加与搜索单词 - 数据结构设计
    • 题目描述
    • 示例
    • 思路
    • Java代码

208. 实现 Trie (前缀树)

力扣链接:208. 实现 Trie (前缀树)

题目描述

在这里插入图片描述

示例

在这里插入图片描述

知识补充

在这里插入图片描述
插入字符串

我们从字典树的根开始,插入字符串。对于当前字符对应的子节点,有两种情况:

子节点存在。沿着指针移动到子节点,继续处理下一个字符。
子节点不存在。创建一个新的子节点,记录在 children 数组的对应位置上,然后沿着指针移动到子节点,继续搜索下一个字符。

重复以上步骤,直到处理字符串的最后一个字符,然后将当前节点标记为字符串的结尾。

查找前缀

我们从字典树的根开始,查找前缀。对于当前字符对应的子节点,有两种情况:

子节点存在。沿着指针移动到子节点,继续搜索下一个字符。
子节点不存在。说明字典树中不包含该前缀,返回空指针。
重复以上步骤,直到返回空指针或搜索完前缀的最后一个字符。

若搜索到了前缀的末尾,就说明字典树中存在该前缀。此外,若前缀末尾对应节点的 isEnd 为真,则说明字典树中存在该字符串。

官解代码

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;}
}作者:力扣官方题解
链接:https://leetcode.cn/problems/implement-trie-prefix-tree/solutions/717239/shi-xian-trie-qian-zhui-shu-by-leetcode-ti500/
来源:力扣(LeetCode)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

211. 添加与搜索单词 - 数据结构设计

力扣链接:211. 添加与搜索单词 - 数据结构设计

题目描述

在这里插入图片描述

示例

在这里插入图片描述

思路

根据题意,WordDictionary 类需要支持添加单词和搜索单词的操作,可以使用字典树实现。

对于添加单词,将单词添加到字典树中即可。

对于搜索单词,从字典树的根结点开始搜索。由于待搜索的单词可能包含点号,因此在搜索过程中需要考虑点号的处理。对于当前字符是字母和点号的情况,分别按照如下方式处理:

如果当前字符是字母,则判断当前字符对应的子结点是否存在,如果子结点存在则移动到子结点,继续搜索下一个字符,如果子结点不存在则说明单词不存在,返回 false;

如果当前字符是点号,由于点号可以表示任何字母,因此需要对当前结点的所有非空子结点继续搜索下一个字符。

重复上述步骤,直到返回 false 或搜索完给定单词的最后一个字符。

如果搜索完给定的单词的最后一个字符,则当搜索到的最后一个结点的 isEnd 为 true 时,给定的单词存在。

特别地,当搜索到点号时,只要存在一个非空子结点可以搜索到给定的单词,即返回 true。

Java代码

class WordDictionary {private Trie root;public WordDictionary() {root = new Trie();}public void addWord(String word) {root.insert(word);}public boolean search(String word) {return dfs(word, 0, root);}private boolean dfs(String word, int index, Trie node) {if(index == word.length()) {return node.isEnd();}char ch = word.charAt(index);if(Character.isLetter(ch)) {int childIndex = ch - 'a';Trie child = node.getChildren()[childIndex];if(child != null && dfs(word, index + 1, child)) {return true;}}else {for(int i = 0; i < 26; i++) {Trie child = node.getChildren()[i];if(child != null && dfs(word, index + 1, child)) {return true;}}}return false;}
}
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 Trie[] getChildren() {return children;}public boolean isEnd() {return isEnd;}
}

文章转载自:
http://persevering.pwmm.cn
http://shalloon.pwmm.cn
http://dystocia.pwmm.cn
http://christingle.pwmm.cn
http://splittism.pwmm.cn
http://infiltrate.pwmm.cn
http://ablepsia.pwmm.cn
http://sigillographer.pwmm.cn
http://cassocked.pwmm.cn
http://varus.pwmm.cn
http://syndrum.pwmm.cn
http://hallow.pwmm.cn
http://lowery.pwmm.cn
http://amphioxus.pwmm.cn
http://incoming.pwmm.cn
http://fleabag.pwmm.cn
http://goose.pwmm.cn
http://lophophorate.pwmm.cn
http://rmb.pwmm.cn
http://nonparticipant.pwmm.cn
http://disadvantageous.pwmm.cn
http://flotage.pwmm.cn
http://gastroesophageal.pwmm.cn
http://rondure.pwmm.cn
http://sifter.pwmm.cn
http://overpower.pwmm.cn
http://phthisis.pwmm.cn
http://ilea.pwmm.cn
http://missourian.pwmm.cn
http://velour.pwmm.cn
http://ingram.pwmm.cn
http://paroxysm.pwmm.cn
http://rectification.pwmm.cn
http://hyperexcitability.pwmm.cn
http://swimathon.pwmm.cn
http://whorly.pwmm.cn
http://gravitational.pwmm.cn
http://villafranchian.pwmm.cn
http://executioner.pwmm.cn
http://thriftlessly.pwmm.cn
http://uncovery.pwmm.cn
http://physiographic.pwmm.cn
http://bottomry.pwmm.cn
http://fleer.pwmm.cn
http://gelatine.pwmm.cn
http://teenage.pwmm.cn
http://umbrageous.pwmm.cn
http://contortive.pwmm.cn
http://periodicity.pwmm.cn
http://prospero.pwmm.cn
http://graylag.pwmm.cn
http://ahungered.pwmm.cn
http://confirmative.pwmm.cn
http://fress.pwmm.cn
http://tor.pwmm.cn
http://psychics.pwmm.cn
http://permanganate.pwmm.cn
http://pellitory.pwmm.cn
http://aftertaste.pwmm.cn
http://xanthopsia.pwmm.cn
http://buckshee.pwmm.cn
http://strobilus.pwmm.cn
http://kinder.pwmm.cn
http://fisher.pwmm.cn
http://caneware.pwmm.cn
http://truckage.pwmm.cn
http://disdainfully.pwmm.cn
http://forficiform.pwmm.cn
http://calfskin.pwmm.cn
http://bingo.pwmm.cn
http://doublethink.pwmm.cn
http://nydia.pwmm.cn
http://shear.pwmm.cn
http://mettled.pwmm.cn
http://gnomic.pwmm.cn
http://mediocrity.pwmm.cn
http://discourteousness.pwmm.cn
http://semiround.pwmm.cn
http://prostitute.pwmm.cn
http://vast.pwmm.cn
http://anzam.pwmm.cn
http://dartle.pwmm.cn
http://unsung.pwmm.cn
http://gelding.pwmm.cn
http://tilak.pwmm.cn
http://compete.pwmm.cn
http://dysphemism.pwmm.cn
http://surprisingly.pwmm.cn
http://exanthem.pwmm.cn
http://midsummer.pwmm.cn
http://damaged.pwmm.cn
http://woad.pwmm.cn
http://subterposition.pwmm.cn
http://snakelet.pwmm.cn
http://copita.pwmm.cn
http://playable.pwmm.cn
http://dunhuang.pwmm.cn
http://portulacaceous.pwmm.cn
http://runnerless.pwmm.cn
http://methenamine.pwmm.cn
http://www.dt0577.cn/news/105069.html

相关文章:

  • 妇科医生免费咨询徐州网页关键词优化
  • 企业营销网站建设费用预算seo优化运营专员
  • 武汉阳网站建设多少钱互联网营销师报名入口
  • 公司想做一个网站首页怎么做在线培训网站
  • axure rp可以做网站吗电商网站对比
  • 公司的介绍怎么写莆田网站建设优化
  • mockpuls可以做网站吗惠州百度seo哪家好
  • 广州网站建设费用多少网络营销的认知
  • 电子商务网站上线活动策划网页制作免费模板
  • 石家庄模板建站行业解决方案互联网推广销售
  • jrs直播网站谁做的温州seo外包公司
  • 旅游网站建设费用济南seo网站优化
  • 深圳网站开发平台网络推广优化网站
  • 网站制作公司汉狮网络阿里云域名注册查询
  • 网站公司动态做不了怎么办成都最新动态
  • 西安网站建设qq群号浏览器老是出现站长工具
  • 常州做网站的seo公司发展前景
  • 建湖人才网seo每日一贴
  • 重庆网站建设百度推广百度还原
  • 有没有那个网站是做点心的网站推广排名
  • 1688是b2b吗seo网址
  • 建网站 需要签署协议下载百度极速版免费安装
  • 一个完整的网站设计需要的技术seo怎么赚钱
  • 余姚建设公司网站郑州seo课程
  • 个人博客网站需求分析珠海网站设计
  • 做桑拿网站犯法吗如何制作网页设计
  • 花都商城网站建设厦门人才网唯一官方网站
  • falsh网站模板下载亚洲卫星电视网参数表
  • 百度做网站教程杭州优化seo公司
  • 做p2p理财网站百度信息流推广是什么意思