1
+ import java .util .Arrays ;
2
+
3
+ class Solution {
4
+ public int [] solution (int [] answers ) {
5
+ int [] answer = {};
6
+ int max = 0 ;
7
+ int count = 0 ;
8
+
9
+ int [] a = new int []{1 ,2 ,3 ,4 ,5 };
10
+ int [] b = new int []{2 ,1 ,2 ,3 ,2 ,4 ,2 ,5 };
11
+ int [] c = new int []{3 ,3 ,1 ,1 ,2 ,2 ,4 ,4 ,5 ,5 };
12
+
13
+ int [] score = new int [3 ];
14
+
15
+ for (int i =0 ; i <answers .length ; i ++){
16
+ if (answers [i ] == a [i %5 ]) score [0 ]++;
17
+ if (answers [i ] == b [i %8 ]) score [1 ]++;
18
+ if (answers [i ] == c [i %10 ]) score [2 ]++;
19
+ }
20
+
21
+ max = Math .max (Math .max (score [0 ], score [1 ]), score [2 ]);
22
+
23
+ for (int i =0 ; i <3 ; i ++){
24
+ if (max == score [i ]) count ++;
25
+ }
26
+ answer = new int [count ];
27
+
28
+ int j = 0 ;
29
+ for (int i =0 ; i <3 ; i ++){
30
+ if (score [i ] == max ) answer [j ++] = i +1 ;
31
+ }
32
+
33
+
34
+ return answer ;
35
+ }
36
+ }
37
+
38
+ // HashMap쓰면 더 빨라지지 않을까 싶었는데 절대 착각이었음..^^
39
+
40
+ // import java.util.*;
41
+
42
+ // class Solution {
43
+ // public int[] solution(int[] answers) {
44
+ // int[] answer = {};
45
+ // int max = 0;
46
+ // int count = 0;
47
+
48
+ // int[] a = new int[]{1,2,3,4,5};
49
+ // int[] b = new int[]{2,1,2,3,2,4,2,5};
50
+ // int[] c = new int[]{3,3,1,1,2,2,4,4,5,5};
51
+
52
+ // int[] score = new int[3];
53
+ // Map<Integer, Integer> score2 = new HashMap<>(){{
54
+ // put(0,0);
55
+ // put(1,0);
56
+ // put(2,0);
57
+ // }};
58
+
59
+ // for(int i=0; i<answers.length; i++){
60
+ // if(answers[i] == a[i%5]) score2.put(0, score2.get(0)+1);
61
+ // if(answers[i] == b[i%8]) score2.put(1, score2.get(1)+1);
62
+ // if(answers[i] == c[i%10]) score2.put(2, score2.get(2)+1);
63
+ // }
64
+
65
+ // max = Collections.max(score2.values());
66
+
67
+ // for(int i=0; i<3; i++){
68
+ // if(max == score2.get(i)) count++;
69
+ // }
70
+ // answer = new int[count];
71
+
72
+ // int j = 0;
73
+ // for(int i=0; i<3; i++){
74
+ // if(score2.get(i) == max) answer[j++] = i+1;
75
+ // }
76
+
77
+
78
+ // return answer;
79
+ // }
80
+ // }
0 commit comments