Skip to content

Commit ee04e8c

Browse files
authored
[20251211] PGM / LV2 / 뉴스 클러스터링 / 이인희
1 parent 3cf1f53 commit ee04e8c

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
```

0 commit comments

Comments
 (0)