Trie树解决字典中查找单词问题
来源:互联网 发布:linux不保存退出 编辑:程序博客网 时间:2024/06/05 10:38
package com.kai.util;import java.util.HashSet;/** * Created by Administrator on 2017/8/4. */public class TrieTree { Node root=new Node(); private class Node{ private Node[] child=new Node[26]; private int count; private HashSet<String> set=new HashSet<String>(); } public void addTrieNode(String s){ Node current=root; for(int index=0;index<s.length();index++){ char c=s.charAt(index); if(current.child[c-'a']==null){ Node node =new Node(); current.child[c-'a']=node; } current=current.child[c-'a']; if(index==s.length()-1){ current.count ++; } // current.set.add(s); } } public int findTrie(String s){ Node current=root; for(int index=0;index<s.length();index++){ char c=s.charAt(index); if(current.child[c-'a']==null){ return 0; } current=current.child[c-'a']; } return current.count; } public static void main(String[] args) { TrieTree tree =new TrieTree(); tree.addTrieNode("hello"); tree.addTrieNode("hello"); tree.addTrieNode("hell"); tree.addTrieNode("world"); tree.addTrieNode("hiiih"); System.out.println(tree.findTrie("hello")); }}
阅读全文
0 0
- Trie树解决字典中查找单词问题
- 字典树(Trie树、单词查找树、前缀树)
- Trie 树(又称字典树,单词查找树)
- Trie 树(又称字典树,单词查找树)
- Trie 树(又称字典树,单词查找树)
- 单词查找树-trie
- Trie树的建立—查找字典中以特定字符串开头的单词数量(java实现)
- Trie—单词查找树
- Trie—单词查找树
- Trie—单词查找树
- Trie—单词查找树
- Trie—单词查找树
- Trie—单词查找树
- 单词查找之Trie树
- Trie,又称字典树、单词查找树,是一种树形结构
- 字典树(Trie查找单词再也不用担心超时了)
- Trie树(单词查找树)
- 【NOI2000T4】单词查找树-trie树
- 大学为什么需要外部协作单位
- 在URL中传递中文参数时传递失败的解决方案
- 13.2—动态规划—Maximum Subarray
- 【博弈】 各种博弈的搬运整理
- 大学如何组织大型信息系统研发的外协?
- Trie树解决字典中查找单词问题
- 13.4—动态规划—Maximal Rectangle
- 正则表达详解及例题
- 13.5—动态规划—Best Time to Buy and Sell Sto III
- MySQL数据类型char与varchar中数字代表的究竟是字节数还是字符数?
- Java 集合系列07之 Stack详细介绍(源码解析)和使用示例
- D
- android 6.0权限全面详细分析和解决方案
- 13.6—动态规划—Interleaving String