-
Notifications
You must be signed in to change notification settings - Fork 31
/
676.java
38 lines (34 loc) · 1001 Bytes
/
676.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
class MagicDictionary {
Set<String> originalSet;
public MagicDictionary() {
originalSet = new HashSet<>();
}
public void buildDict(String[] dictionary) {
for(String str: dictionary){
originalSet.add(str);
}
}
public boolean search(String searchWord) {
for(String str: originalSet){
int count = 0;
if(searchWord.length() != str.length()){
continue;
}
for(int i=0;i < str.length();i++){
if(str.charAt(i) != searchWord.charAt(i)){
count++;
}
}
if(count == 1){
return true;
}
}
return false;
}
}
/**
* Your MagicDictionary object will be instantiated and called as such:
* MagicDictionary obj = new MagicDictionary();
* obj.buildDict(dictionary);
* boolean param_2 = obj.search(searchWord);
*/