Skip to content

Commit 4995938

Browse files
authored
[20251103] PGM / Lv2 / [1차] 뉴스 클러스터링 / 이강현
1 parent 35e70b9 commit 4995938

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
```java
2+
import java.util.*;
3+
4+
class Solution {
5+
public int solution(String str1, String str2) {
6+
List<String> A = new ArrayList<>();
7+
List<String> B = new ArrayList<>();
8+
9+
for(int i = 0; i + 1 < str1.length(); i++){
10+
String temp = str1.substring(i, i + 2);
11+
if(!validation(temp.charAt(0)) || !validation(temp.charAt(1))) continue;
12+
A.add(temp.toLowerCase());
13+
}
14+
15+
for(int i = 0; i + 1 < str2.length(); i++){
16+
String temp = str2.substring(i, i + 2);
17+
if(!validation(temp.charAt(0)) || !validation(temp.charAt(1))) continue;
18+
B.add(temp.toLowerCase());
19+
}
20+
21+
if(A.isEmpty() && B.isEmpty()) {
22+
return 65536;
23+
}
24+
25+
Collections.sort(A);
26+
Collections.sort(B);
27+
28+
int intersection = 0;
29+
int a = 0;
30+
int b = 0;
31+
while(a < A.size() && b < B.size()){
32+
int compare = A.get(a).compareTo(B.get(b));
33+
if(compare == 0){
34+
intersection++;
35+
a++;
36+
b++;
37+
} else if(compare < 0){
38+
a++;
39+
} else {
40+
b++;
41+
}
42+
}
43+
44+
int union = A.size() + B.size() - intersection;
45+
46+
return (int)((double)intersection / union * 65536);
47+
}
48+
49+
public boolean validation(char c){
50+
return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z');
51+
}
52+
}
53+
```

0 commit comments

Comments
 (0)