
trie
文章平均质量分 68
flyatcmu
这个作者很懒,什么都没留下…
展开
-
Design File System
You are asked to design a file systemthat allows you to create new paths and associate them with different values.The format of a path isone or more concatenated strings of the form:/followed by one or more lowercase English letters. For example, "/l...原创 2022-05-03 12:34:09 · 224 阅读 · 0 评论 -
Strings Differ by One Character
Given a list of stringsdictwhere all the strings are of the same length.Returntrueif there are 2 strings that only differ by 1 character in the same index, otherwise returnfalse.Example 1:Input: dict = ["abcd","acbd", "aacd"]Output: trueExp...原创 2022-04-30 08:29:16 · 194 阅读 · 0 评论 -
Stream of Characters
Implement theStreamCheckerclass as follows:StreamChecker(words): Constructor, init the data structure with the given words. query(letter): returns true if and only if for somek >= 1, the lastkcharacters queried (in order from oldest to newest, i...原创 2020-06-11 13:39:44 · 247 阅读 · 0 评论 -
Implement Magic Dictionary
Implement a magic directory withbuildDict, andsearchmethods.For the methodbuildDict, you'll be given a list of non-repetitive words to build a dictionary.For the methodsearch, you'll be given a word, and judge whether if you modifyexactlyone cha...原创 2020-05-22 12:00:25 · 156 阅读 · 0 评论 -
Design Search Autocomplete System
Design a search autocomplete system for a search engine. Users may input a sentence (at least one word and end with a special character'#'). Foreach characterthey typeexcept '#', you need to retur...原创 2020-04-13 15:13:28 · 378 阅读 · 0 评论 -
Search Suggestions System
Given an array of stringsproductsand a stringsearchWord. We want to design a system that suggests at most three product names fromproductsafter each character ofsearchWordis typed. Suggested pr...原创 2020-04-12 05:46:38 · 356 阅读 · 0 评论 -
Concatenated Words
Given a list of words (without duplicates), please write a program that returns all concatenated words in the given list of words.A concatenated word is defined as a string that is comprised entirel...原创 2020-04-11 02:56:10 · 267 阅读 · 0 评论 -
Prefix and Suffix Search
Given manywords,words[i]has weighti.Design a classWordFilterthat supports one function,WordFilter.f(String prefix, String suffix). It will return the word with givenprefixandsuffixwith ma...原创 2020-03-12 12:12:12 · 597 阅读 · 0 评论 -
Longest word in Dictionary
Given a list of stringswordsrepresenting an English Dictionary, find the longest word inwordsthat can be built one character at a time by other words inwords. If there is more than one possible a...原创 2020-03-11 12:25:42 · 371 阅读 · 0 评论 -
Trie 类型的题目总结
trie字典树可以用来查找单词或者搜索剪枝用。Implement Trie (Prefix Tree)实现一个 Trie,包含insert,search, 和startsWith这三个方法。思路:模板必须记住;没有儿子建立儿子,有儿子走儿子;public class Trie { private class TrieNode { Trie...原创 2020-01-10 16:02:49 · 1184 阅读 · 1 评论 -
Word Squares
Given a set of wordswithout duplicates, find allword squaresyou can build from them.A sequence of words forms a valid word square if the kth row and column read the exact same string, where 0 ≤ k...原创 2020-01-10 15:52:54 · 359 阅读 · 0 评论 -
Word Search II
Given a 2D board and a list of words from the dictionary, find all words in the board.Each word must be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horiz...原创 2016-08-09 13:46:00 · 481 阅读 · 0 评论 -
K Edit Distance
Given a set of strings which just has lower case letters and a target string, output all the strings for each the edit distance with the target no greater thank.You have the following 3 operations ...原创 2019-12-12 14:13:25 · 689 阅读 · 0 评论 -
Add and Search Word - Data structure design
Design a data structure that supports the following two operations:void addWord(word)bool search(word)search(word) can search a literal word or a regular expression string containing only le...原创 2016-09-11 11:40:17 · 488 阅读 · 0 评论 -
shortest unique prefix
Given an array of words, find all shortest unique prefixes to represent each word in the given array. Assume that no word is prefix of another.Input: arr[] = {"zebra", "dog", "duck", "dove"}Output...原创 2019-05-14 14:46:44 · 311 阅读 · 0 评论 -
Implement Trie (Prefix Tree)
Implement a trie withinsert,search, andstartsWithmethods.Note:You may assume that all inputs are consist of lowercase lettersa-z.思路:首先建立一个TrieNode class,里面包含26个TireNode array,然后build trie...原创 2016-09-11 09:56:43 · 325 阅读 · 0 评论