File tree Expand file tree Collapse file tree 1 file changed +20
-18
lines changed
src/main/java/com/fishercoder/solutions Expand file tree Collapse file tree 1 file changed +20
-18
lines changed Original file line number Diff line number Diff line change 38
38
true
39
39
*/
40
40
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
+ }
41
57
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 ) {
48
59
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 ;
51
62
} else {
52
- dict .put (key , word );
63
+ return dict .get (key ) != "" && dict . get ( key ). equals ( word );
53
64
}
54
65
}
55
66
}
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
- }
65
67
}
66
68
67
69
public class ValidWordAbbrSolution2 {
You can’t perform that action at this time.
0 commit comments