신고 결과 받기(프로그래머스) 연습기
import java.util.*;
class Solution {
public int[] solution(String[] id_list, String[] report, int k) {
int[] answer = new int[id_list.length]; //정지 메일을 받은 횟수 배열
int[] be = new int[id_list.length];
Set<String> set= new HashSet<String>();
for(int i=0 ; i<report.length ; i++){
String[] arr = report[i].split("\\s");
int c=set.size();
set.add(report[i]);
if(c != set.size()){
int index=Arrays.asList(id_list).indexOf(arr[1]);
be[index]++;
}
}
List<String> fire=new ArrayList<String>();
for(int i=0 ; i<id_list.length ; i++){
if(k<=be[i]){
fire.add(id_list[i]);
}
}
Set<String> user=new HashSet<String>();
int count=0;
for(int i=0 ; i<report.length;i++){
String[] temp=report[i].split("\\s");
count = user.size();
user.add(report[i]);
for(int j=0; j<fire.size() ; j++){
if(temp[1].equals(fire.get(j)) && count != user.size()){
int index_f = Arrays.asList(id_list).indexOf(temp[0]);
answer[index_f]++;
}
}
}
return answer;
}
}
결과는 통과했지만,, 엄청 비효율적이고 더럽고 조잡한 코드란거 안다,,
거의 8시간넘게 걸린것같더,,
일단 마무리짓고 찾아보니 대부분 map으로 해결하는것 같움
- map으로 다시 구성해보기
- 코드 가독성/효율성 높여보기