本文共 550 字,大约阅读时间需要 1 分钟。
思路:
就是前缀树。如果碰到点符号就遍历好了,只要有一个返回true就返回true。。class TrieNode { // Initialize your data structure here. TrieNode charecters[]; boolean end; public TrieNode() { charecters=new TrieNode[26]; end=false; }}public class WordDictionary { private TrieNode root; public WordDictionary() { root = new TrieNode(); root.charecters=new TrieNode[26]; } // Adds a word into the data structure. public void addWord(String word) { int n=word.length(); TrieNode temp=root; for(int i=0;i
转载地址:http://jduvb.baihongyu.com/