-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTriesPracticeQues.java
More file actions
34 lines (29 loc) · 893 Bytes
/
Copy pathTriesPracticeQues.java
File metadata and controls
34 lines (29 loc) · 893 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
public class TriesPracticeQues {
static class Node{
Node children[] = new Node[26];
boolean eow = false;
public Node(){
for(int i = 0; i< 26; i++){
children[i] = null;
}
}
}
public static Node root = new Node();
public static void insert(String word){
Node curr = root;
for(int i = 0; i< word.length(); i++){
int idx = word.charAt(i) - 'a';
if (curr.children[idx] == null){
curr.children[idx] = new Node();
}
curr = curr.children[idx];
}
curr.eow = true;
}
public static void main(String[] args) {
String strs[] = {"eat" , "tea" , "tan" , "ate" , "nat", "bat"};
for(int i = 0; i< strs.length; i++){
insert(strs[i]);
}
}
}