-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxorTree.java
59 lines (48 loc) · 1.22 KB
/
xorTree.java
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import java.util.Scanner;
import java.util.*;
class TrieNode {
TrieNode children[];
Hashtable<Integer, Integer> hijos;
int index;
int k;
TrieNode(int m, int k){
index=0;
children=new TrieNode[m];
hijos= new Hashtable<Integer, Integer>();
this.k=k;
}
public void insert(int []a, int i)
{
if(i<a.length){
if(this.hijos.containsKey(a[i])){
int x=this.hijos.get(a[i]);
this.children[x].insert(a, i+1);
}else{
hijos.put(a[i], index);
children[index]=new TrieNode(this.children.length, a[i]);
this.children[index].insert(a, i+1);
index++;
}
}
}
public int nodes(){
int ans=1;
for(int i=0;i<index; i++){
ans+=children[i].nodes();
}
return ans;
}
public String toString(){
String ans= "("+String.valueOf(k)+" ";
for(int i=0;i<index; i++){
ans+=children[i].toString();
}
ans+=" )";
return ans;
}
}
class xorTree{
public static void main(String[] args) {
Scanner in= new Scanner(System.in);
}
}