Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options answers only not deleted user 12390

A tree-like data structure used to hold an associative array, also called a Prefix Tree.

2 votes

Trie structure with three classes

Naming You can drop "Trie" from these methods: buildTrie traverseTrie The name of the class already implies that you're working with a Trie. In searchWord the term "Word" seems also pointless. … trie; public TrieTest() { trie = new Trie(); trie.build(new HashSet<>(Arrays.asList("CAT", "CATWOMAN", "CATERER", "DOT", "DOG", "DOC"))); } @Test public void test_CAX …
janos's user avatar
  • 112k
2 votes

Java Trie Implementation

class Trie { private final Map<Character, HashMap> root = new HashMap<>(); private final Character END_CHARACTER = '$'; public Trie(String s) { add(s); } public Trie(Collection …
janos's user avatar
  • 112k
2 votes

Leetcode: Map Sum Pairs C#

Traverse the trie letter by letter as before, and for each node traversed, subtract prev and add val. Set the new value in values. …
janos's user avatar
  • 112k
4 votes
Accepted

LeetCode: Replace Words Trie C#

It would be better if it looked more like this: public string ReplaceWords(IList<string> dict, string sentence) { Trie trie = new Trie(); // for each word in dict, trie.add(word) // for … And I don't see mistakes in the trie implementation degrade its performance significantly. The overall time and space complexity of the solution is dominated by that of the trie. …
janos's user avatar
  • 112k
3 votes

Leet Code 139 (Word Break) using a trie with recursion

Take advantage of the trie The code doesn't take advantage of the trie to its full potential. … That is, each iteration starts searching in the trie from the top. …
janos's user avatar
  • 112k