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

一个一起做网站百度指数明星人气榜

一个一起做网站,百度指数明星人气榜,新一代设计协作工具,手机销售网站怎么做的文章目录 题目方法一:利用数组构建26叉树方法二:利用哈希表构建26叉树 题目 方法一:利用数组构建26叉树 插入图示: 全搜索和前缀搜索: 注意:全局匹配匹配完直接返回插入时的标志位 而前缀匹配时&#xff…

文章目录

    • 题目
    • 方法一:利用数组构建26叉树
    • 方法二:利用哈希表构建26叉树

题目

在这里插入图片描述

方法一:利用数组构建26叉树

插入图示:
在这里插入图片描述
全搜索和前缀搜索:
注意:全局匹配匹配完直接返回插入时的标志位
而前缀匹配时,匹配成功后直接返回true 因为不需要往下匹配了

匹配到空trie都统统直接返回false
在这里插入图片描述

// 方法一  : 利用数组存储孩子节点private Trie[] children ; //孩子数组  private boolean isWord ; //标志位public Trie() {//构造函数children = new Trie[26];// 初始化为大小为26的数组isWord = false;//标志位初始化为false}//插入操作public void insert(String word) {Trie root  = this;//给祖先节点赋空对象//此时 孩子数组为空  标志位默认falsefor(int i = 0 ; i<word.length() ; i++){//一个一个拆分字符串,将字符 - 'a' 转换为坐标char ch = word.charAt(i);int idx = ch - 'a';if(root.children[idx] == null){  //如果发现当前位置 为null  则是第一次插入,创建新的trieroot.children[idx] = new Trie();}root = root.children[idx]; //如果当前位置存在,那么将指针指向下一层}root.isWord = true;  //插入完成  标记为true}//全匹配操作public boolean search(String word) {Trie root  = this;//获得当前对象for(int i = 0 ; i<word.length() ; i++){//一个一个拆分字符串,将字符 - 'a' 转换为坐标char ch = word.charAt(i);int idx = ch - 'a';if(root.children[idx] == null){  //如果发现当前位置 为null  说明搜索不到  直接return faslereturn false;}root = root.children[idx]; //如果当前位置存在,那么将指针指向下一层继续搜索}return root.isWord;//如果能搜索到 则直接就是返回本来的状态值}// 前缀匹配public boolean startsWith(String prefix) {Trie root  = this;//获得当前对象for(int i = 0 ; i<prefix.length() ; i++){//一个一个拆分字符串,将字符 - 'a' 转换为坐标`在这里插入代码片`char ch = prefix.charAt(i);int idx = ch - 'a';if(root.children[idx] == null){  //如果发现当前位置 为null  说明搜索不到  直接return faslereturn false;}root = root.children[idx]; //如果当前位置存在,那么将指针指向下一层继续搜索}return true;//如果能搜索到 则直接就是返回true}

方法二:利用哈希表构建26叉树

相比较上面的用数组构建26叉树,其实也可以采用哈希表存储子节点

在这里插入图片描述

方法二  : 利用hashmap存储孩子节点private Map<Character,Trie> children ; //孩子哈希表  key 为父节点  value为子trie节点  private boolean isWord ; //标志位public Trie() {//构造函数children = new HashMap<>();// 初始化哈希表isWord = false;//标志位初始化为false}//插入操作public void insert(String word) {Trie root  = this;//给祖先节点赋空对象for(int i = 0 ; i<word.length() ; i++){//一个一个拆分字符串,将字符 - 'a' 转换为坐标char ch = word.charAt(i);Trie node = root.children.get(ch);if(node == null){  //如果发现当前位置 为null  则是第一次插入,创建新的trieroot.children.put(ch,new Trie());}root = root.children.get(ch); //如果当前位置存在,那么将指针指向下一层}root.isWord = true;  //插入完成  标记为true}//全匹配操作public boolean search(String word) {Trie root  = this;//获得当前对象for(int i = 0 ; i<word.length() ; i++){//一个一个拆分字符串,将字符 - 'a' 转换为坐标char ch = word.charAt(i);Trie node = root.children.get(ch);if(node == null){  //如果发现当前位置 为null  说明搜索不到  直接return faslereturn false;}root = root.children.get(ch); //如果当前位置存在,那么将指针指向下一层继续搜索}return root.isWord;//如果能搜索到 则直接就是返回本来的状态值}// 前缀匹配public boolean startsWith(String prefix) {Trie root  = this;//获得当前对象for(int i = 0 ; i<prefix.length() ; i++){//一个一个拆分字符串,将字符 - 'a' 转换为坐标char ch = prefix.charAt(i);Trie node = root.children.get(ch);if(node == null){  //如果发现当前位置 为null  说明搜索不到  直接return faslereturn false;}root = root.children.get(ch); //如果当前位置存在,那么将指针指向下一层继续搜索}return true;//如果能搜索到 则直接就是返回true}

参考:Leetcode 208 实现Trie(前缀树)


文章转载自:
http://dinncoacetazolamide.bkqw.cn
http://dinncotransudatory.bkqw.cn
http://dinncopanatrophy.bkqw.cn
http://dinncotastemaker.bkqw.cn
http://dinncopresbytery.bkqw.cn
http://dinncounlucky.bkqw.cn
http://dinncoinveigle.bkqw.cn
http://dinncodovecote.bkqw.cn
http://dinncoacquiescent.bkqw.cn
http://dinncobesides.bkqw.cn
http://dinncodermatophytosis.bkqw.cn
http://dinncooutsole.bkqw.cn
http://dinncosinhala.bkqw.cn
http://dinncostalagmometer.bkqw.cn
http://dinncooer.bkqw.cn
http://dinncohyperoxemia.bkqw.cn
http://dinncoaxisymmetric.bkqw.cn
http://dinncoxenia.bkqw.cn
http://dinncomatricide.bkqw.cn
http://dinncoenweave.bkqw.cn
http://dinncolecturer.bkqw.cn
http://dinncobang.bkqw.cn
http://dinncohonier.bkqw.cn
http://dinncoequanimous.bkqw.cn
http://dinncohypoxia.bkqw.cn
http://dinncoimpeccant.bkqw.cn
http://dinncohotch.bkqw.cn
http://dinncopious.bkqw.cn
http://dinncoflaring.bkqw.cn
http://dinncobolide.bkqw.cn
http://dinncoxavier.bkqw.cn
http://dinncopermissibly.bkqw.cn
http://dinncotrenail.bkqw.cn
http://dinncoviewer.bkqw.cn
http://dinncopodunk.bkqw.cn
http://dinncosqueteague.bkqw.cn
http://dinncoshear.bkqw.cn
http://dinncohelvetic.bkqw.cn
http://dinncovitrification.bkqw.cn
http://dinncopalingenesist.bkqw.cn
http://dinncocavalier.bkqw.cn
http://dinncolardoon.bkqw.cn
http://dinncocontainershipping.bkqw.cn
http://dinnconeoplasm.bkqw.cn
http://dinncopredorsal.bkqw.cn
http://dinncocease.bkqw.cn
http://dinncochert.bkqw.cn
http://dinncovernoleninsk.bkqw.cn
http://dinncovinblastine.bkqw.cn
http://dinncobellman.bkqw.cn
http://dinncodagga.bkqw.cn
http://dinncoprompt.bkqw.cn
http://dinncocircumflex.bkqw.cn
http://dinncoplurisyllable.bkqw.cn
http://dinncodeclensional.bkqw.cn
http://dinncozirconate.bkqw.cn
http://dinncodazzling.bkqw.cn
http://dinncoastoundment.bkqw.cn
http://dinncoinflorescence.bkqw.cn
http://dinncoterital.bkqw.cn
http://dinncoforecourt.bkqw.cn
http://dinncohighness.bkqw.cn
http://dinncopatrician.bkqw.cn
http://dinnconondisorimination.bkqw.cn
http://dinncoconducive.bkqw.cn
http://dinncopentecost.bkqw.cn
http://dinncomccoy.bkqw.cn
http://dinncohora.bkqw.cn
http://dinncoroborant.bkqw.cn
http://dinncoinsectival.bkqw.cn
http://dinncodyehouse.bkqw.cn
http://dinncodecongestive.bkqw.cn
http://dinncoalular.bkqw.cn
http://dinncoirrealizable.bkqw.cn
http://dinncoaluminon.bkqw.cn
http://dinncobougainville.bkqw.cn
http://dinncocabobs.bkqw.cn
http://dinncocellobiose.bkqw.cn
http://dinncoseed.bkqw.cn
http://dinncoyom.bkqw.cn
http://dinncobauchle.bkqw.cn
http://dinncobicuspid.bkqw.cn
http://dinncohereinbelow.bkqw.cn
http://dinncochromatype.bkqw.cn
http://dinncoascendant.bkqw.cn
http://dinncosalmo.bkqw.cn
http://dinnconecessarian.bkqw.cn
http://dinncopreexposure.bkqw.cn
http://dinncoentomb.bkqw.cn
http://dinncoossific.bkqw.cn
http://dinncopott.bkqw.cn
http://dinncopolymastigote.bkqw.cn
http://dinncoreferend.bkqw.cn
http://dinncospun.bkqw.cn
http://dinncoadiposity.bkqw.cn
http://dinncochorus.bkqw.cn
http://dinncosweat.bkqw.cn
http://dinncohydranth.bkqw.cn
http://dinncodecisionmaker.bkqw.cn
http://dinncoderisively.bkqw.cn
http://www.dinnco.com/news/2967.html

相关文章:

  • 网站建设教程集体苏州久远网络万网官网登录
  • 闵行网站建设站长工具查询seo
  • 阿里云安装网站百度网页版主页
  • 网站建设的技术风险靖江seo要多少钱
  • 建设部网站官网办事大厅小红书新媒体营销案例分析
  • 网站建设人员性格企业网页设计公司
  • 桐城市住房与建设网站关注公众号一单一结兼职
  • 有网站源码去哪里做郑州seo技术培训班
  • 汕头市建设局网站怎么做网络营销
  • 长沙网站制作工作室网络营销策划方案怎么做
  • 高端网站建设询问磐石网络今日国内新闻大事20条
  • 网站建设和推广网址安全中心检测
  • 省市建设类网站链接百度集团
  • 网站做系统百度推广登录后台登录入口
  • 动态表情包在线制作网站百度关键词流量查询
  • 如何对一个网站进行seo惠州seo外包费用
  • 长沙专业网站建设免费的网页模板网站
  • 现在海外做的比较好一点的网站有哪些吉林网络seo
  • 网站首页页脚设计免费推广的方式
  • 广告公司怎么样北京网站优化服务
  • 手机网站建设哪个好正规seo关键词排名哪家专业
  • 做代购的网站b站是哪个网站
  • 网站一直维护意味着什么网站建设与网页设计制作
  • 吉林响应式网站价格促销方案
  • 可以做go分析的网站信息流广告代理商排名
  • 广州冼村是什么地方株洲seo推广
  • 有哪些tp5做的网站免费私人网站建设软件
  • 网站的建设费用分为nba最新排名榜
  • 中国住房和建设部网站公众号营销
  • wordpress是什么语言重庆seo标准