forked from fluency03/leetcode-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrieNode.java
More file actions
35 lines (29 loc) · 684 Bytes
/
TrieNode.java
File metadata and controls
35 lines (29 loc) · 684 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
35
/**
* Definition for a trie (prefix tree) node.
*
* https://leetcode.com/articles/implement-trie-prefix-tree/
*/
public class TrieNode {
// R links to node children
private TrieNode[] links;
private final int R = 26;
private boolean isLeaf;
public TrieNode() {
links = new TrieNode[R];
}
public boolean containsKey(char c) {
return links[c -'a'] != null;
}
public TrieNode get(char c) {
return links[c -'a'];
}
public void put(char c, TrieNode node) {
links[c -'a'] = node;
}
public void setLeaf() {
isLeaf = true;
}
public boolean isLeaf() {
return isLeaf;
}
}