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

河南网站建设服务广告电话

河南网站建设服务,广告电话,专业做app下载网站,旅游网站建设与网页设计https://leetcode.cn/problems/design-add-and-search-words-data-structure/description/?envTypestudy-plan-v2&envIdtop-interview-150思路:就是然我们设计一个字典树,和上一题基本一样,之前使用的是树的方式来构建字典树。 class M…
https://leetcode.cn/problems/design-add-and-search-words-data-structure/description/?envType=study-plan-v2&envId=top-interview-150

思路:就是然我们设计一个字典树,和上一题基本一样,之前使用的是树的方式来构建字典树。

class Main{class WordDictionary {private WordDictionary[] children;private boolean isEnd;public WordDictionary() {this.children = new WordDictionary[26];this.isEnd = false;}public void addWord(String word) {WordDictionary 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 WordDictionary();}node = node.children[index];}node.isEnd = true;}public boolean search(String word) {WordDictionary node = this;return search2(node, word, 0);}public boolean search2(WordDictionary node, String word, int index) {if(index == word.length()) {return node.isEnd;}//遇到'.' 的逻辑:遍历该层的所有非空节点只要所有情况中存在匹配情况就返回true(意思就是只有true才是终点)char ch = word.charAt(index);if(ch == '.') {for(WordDictionary child : node.children) {if( child != null) {if(search2(child, word, index + 1)) {return true;}}}} else {if(node.children[ch - 'a'] != null && search2(node.children[ch - 'a'], word, index + 1)) {return true;}}return false;}}public static void main(String[] args) {Main main = new Main();WordDictionary wordDictionary = main.new WordDictionary();wordDictionary.addWord("bad");wordDictionary.addWord("dad");wordDictionary.addWord("mad");System.out.println(wordDictionary.search("pad")); // return falseSystem.out.println(wordDictionary.search("bad")); // return trueSystem.out.println(wordDictionary.search(".ad")); // return trueSystem.out.println(wordDictionary.search("b..")); // return true}}

http://www.dtcms.com/wzjs/289519.html

相关文章:

  • 政府网站建设督查报告电商网站订烟平台
  • 做图片网站 服务器如何做网络推广推广
  • 网站建设策目标seo服务公司上海
  • 莱芜58同城招聘网最新招聘湖南seo推广软件
  • 重庆帝一网络网站建设专家网站推广seo教程
  • 学校网站php源码天津优化公司
  • 2015做哪些网站致富做网页怎么做
  • 建立购物网站google官网下载
  • 成都网站建设 3e网络视频剪辑培训
  • beego 网站开发重庆seo结算
  • 什么软件可以做企业网站新野seo公司
  • wordpress网站很慢广告推广平台网站
  • 佳木斯做网站自己的网站怎么推广
  • 主做销售招聘的招聘网站有哪些关键词优化外包服务
  • 网站 真实性2024政治时政热点
  • 数据库怎么做网站长沙网站seo公司
  • 曹县做网站建设网推接单平台
  • 网站留言板块怎么做seo研究中心倒闭
  • 住房建设部官方网站seo系统是什么意思
  • 外贸商城网站查询网 网站查询
  • 成都网站建设市场seo关键词优化费用
  • 深圳互联网做网站seo怎么赚钱
  • 福永网站推广购买友情链接网站
  • 网站建设分几步微商店铺怎么开通
  • 闽侯县住房和城乡建设局官方网站优化关键词排名
  • 人大家网站建设广州seo和网络推广
  • 天津做网站优化的公司免费seo网站自动推广软件
  • 包装设计网官网南京seo排名优化公司
  • 西安h5响应式网站全网营销推广软件
  • 做平面设计图的网站网页模板代码