Skip to content

Commit 23c6ae1

Browse files
committed
[add]카카오 구현
1 parent 192c4cd commit 23c6ae1

14 files changed

Lines changed: 179 additions & 15 deletions

‎.idea/workspace.xml‎

Lines changed: 26 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎BoostCamp/src/Main.java‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
1+
import java.util.Collections;
2+
import java.util.HashMap;
3+
import java.util.List;
4+
import java.util.Map;
5+
import java.util.ArrayList;
6+
17
public class Main {
28
public static void main(String[] args) {
3-
System.out.println("Hello world!");
9+
10+
Map<Integer,Integer> map1 = new HashMap<>();
11+
Map<Integer,Integer> map2 = new HashMap<>();
12+
map1.put(1,9);
13+
map1.put(2,7);
14+
map1.put(3,4);
15+
map1.put(4,0);
16+
map1.put(5,1);
17+
List<Integer> list= new ArrayList<>();
18+
list.add(1);
19+
list.add(2);
20+
list.add(3);
21+
list.add(4);
22+
list.add(5);
23+
24+
Collections.sort(list, (o1, o2) -> (map1.get(o1)).compareTo(map1.get(o2)));
25+
26+
System.out.println(list.toString());
427
}
528
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import java.util.*;
2+
3+
4+
public class 구현_카카오뉴스클러스터링 {
5+
6+
class Solution {
7+
public int solution(String str1, String str2) {
8+
ArrayList<String> multiSet1 = new ArrayList<>();
9+
ArrayList<String> multiSet2 = new ArrayList<>();
10+
ArrayList<String> union = new ArrayList<>();
11+
ArrayList<String> intersection = new ArrayList<>();
12+
13+
str1 = str1.toLowerCase();
14+
str2 = str2.toLowerCase();
15+
16+
for(int i = 0 ; i < str1.length() - 1 ; ++i){
17+
char first = str1.charAt(i);
18+
char second = str1.charAt(i + 1);
19+
20+
if(first >= 'a' && first <= 'z' &&
21+
second >= 'a' && second <= 'z'){
22+
multiSet1.add(first + "" + second);
23+
}
24+
}
25+
26+
for(int i = 0 ; i < str2.length() - 1 ; ++i){
27+
char first = str2.charAt(i);
28+
char second = str2.charAt(i + 1);
29+
30+
if(first >= 'a' && first <= 'z' &&
31+
second >= 'a' && second <= 'z'){
32+
multiSet2.add(first + "" + second);
33+
}
34+
}
35+
36+
Collections.sort(multiSet1);
37+
Collections.sort(multiSet2);
38+
39+
for(String s : multiSet1){
40+
if(multiSet2.remove(s)){
41+
intersection.add(s);
42+
}
43+
union.add(s);
44+
}
45+
46+
for(String s : multiSet2){
47+
union.add(s);
48+
}
49+
50+
double jakard = 0;
51+
52+
if(union.size() == 0) {
53+
jakard = 1;
54+
} else {
55+
jakard = (double)intersection.size() / (double)union.size();
56+
}
57+
58+
return (int)(jakard * 65536);
59+
}
60+
}
61+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import java.util.*;
2+
3+
4+
public class 구현_카카오실행률 {
5+
6+
class Solution {
7+
public int[] solution(int N, int[] stages) {
8+
int[] answer = {};
9+
10+
Arrays.sort(stages);
11+
// System.out.println(Arrays.toString(stages));
12+
13+
Map<Integer,Double> failMap = new HashMap<>();
14+
15+
int count = 0;
16+
int n = stages[0];
17+
for(int i=0;i<stages.length; i++){
18+
if( n == N+1){
19+
break;
20+
}
21+
if (n != stages[i]){
22+
double fail = (double) count / (stages.length - i + count);
23+
// System.out.println(fail);
24+
failMap.put(n, fail);
25+
n = stages[i];
26+
count = 0;
27+
}
28+
count++;
29+
}
30+
if (n <= N){
31+
failMap.put(n,1.0);
32+
}
33+
// System.out.println(failMap.keySet());
34+
// System.out.println(failMap.get(4));
35+
36+
for (int i=1;i<=N;i++){
37+
failMap.put(i,failMap.getOrDefault(i,0.0));
38+
}
39+
40+
41+
List<Integer> list = new ArrayList<>();
42+
for (int i=0;i<N;i++){
43+
// A[i] = i+1;
44+
list.add(i+1);
45+
}
46+
47+
Collections.sort(list, (o1, o2) -> (failMap.get(o2)).compareTo(failMap.get(o1)));
48+
49+
int[] A = new int[list.size()];
50+
for (int i=0;i<list.size();i++){
51+
A[i] = list.get(i);
52+
}
53+
54+
return A;
55+
}
56+
}
57+
}
1.74 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1.56 KB
Binary file not shown.

0 commit comments

Comments
 (0)