8000 refactor 288 · nabinkumar/Leetcode@3c06067 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3c06067

Browse files
refactor 288
1 parent 3297cdc commit 3c06067

File tree

1 file changed

+20
-18
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+20
-18
lines changed

src/main/java/com/fishercoder/solutions/_288.java

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,30 +38,32 @@
3838
true
3939
*/
4040
public class _288 {
41+
public static class Solution1 {
42+
43+
public class ValidWordAbbrSolution1 {
44+
private Map<String, String> dict;
45+
46+
public ValidWordAbbrSolution1(String[] dictionary) {
47+
dict = new HashMap();
48+
for (String word : dictionary) {
49+
String key = word.length() <= 2 ? word : (word.charAt(0) + String.valueOf(word.length() - 2) + word.charAt(word.length() - 1));
50+
if (dict.containsKey(key) && !dict.get(key).equals(word)) {
51+
dict.put(key, "");
52+
} else {
53+
dict.put(key, word);
54+
}
55+
}
56+
}
4157

42-
public class ValidWordAbbrSolution1 {
43-
private Map<String, String> dict;
44-
45-
public ValidWordAbbrSolution1(String[] dictionary) {
46-
dict = new HashMap();
47-
for (String word : dictionary) {
58+
private boolean isUnique(String word) {
4859
String key = word.length() <= 2 ? word : (word.charAt(0) + String.valueOf(word.length() - 2) + word.charAt(word.length() - 1));
49-
if (dict.containsKey(key) && !dict.get(key).equals(word)) {
50-
dict.put(key, "");
60+
if (!dict.containsKey(key)) {
61+
return true;
5162
} else {
52-
dict.put(key, word);
63+
return dict.get(key) != "" && dict.get(key).equals(word);
5364
}
5465
}
5566
}
56-
57 75BA -
public boolean isUnique(String word) {
58-
String key = word.length() <= 2 ? word : (word.charAt(0) + String.valueOf(word.length() - 2) + word.charAt(word.length() - 1));
59-
if (!dict.containsKey(key)) {
60-
return true;
61-
} else {
62-
return dict.get(key) != "" && dict.get(key).equals(word);
63-
}
64-
}
6567
}
6668

6769
public class ValidWordAbbrSolution2 {

0 commit comments

Comments
 (0)
0