File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.util.* ;
3+
4+ class Solution {
5+ private static Map<String , int[]> map;
6+ public int solution (String str1 , String str2 ) {
7+ map = new HashMap<String , int[]> ();
8+ pushSet(str1, 0 );
9+ pushSet(str2, 1 );
10+
11+ int bunja = 0 ;
12+ int bunmo = 0 ;
13+ for (Map . Entry<String , int[]> entry: map. entrySet()){
14+ int [] v = entry. getValue();
15+ bunja += Math . min(v[0 ], v[1 ]);
16+ bunmo += Math . max(v[0 ], v[1 ]);
17+ }
18+
19+ if (bunmo == 0 )
20+ return 65536 ;
21+
22+ return (int )( (bunja / (float )bunmo) * 65536 );
23+ }
24+
25+ private void pushSet (String str , int index ){
26+ char [] cs = str. toCharArray();
27+ for (int i = 0 ; i < cs. length - 1 ; i++ ){
28+ char a = cs[i];
29+ char b = cs[i + 1 ];
30+ if (! Character . isLetter(a) || ! Character . isLetter(b))
31+ continue ;
32+ a = Character . toLowerCase(a);
33+ b = Character . toLowerCase(b);
34+
35+ String key = " " + a + b;
36+
37+ if (! map. containsKey(key))
38+ map. put(key, new int [2 ]);
39+
40+ map. get(key)[index]++ ;
41+ }
42+ }
43+ }
44+
45+ ```
You can’t perform that action at this time.
0 commit comments