[Programmers] - 신고 결과 받기
문제
“카카오 블라인드 채용” 문제이다.
42seoul하느라 프로그래머스가 너무 오랫만이다. 핑계다.
오랫만에 하니 흥미로웠다.
1레벨 치고 어려운 편인가.
코드
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.ArrayList;
class Solution {
public int[] solution(String[] id_list, String[] report, int k) {
int[] answer = new int[id_list.length];
LinkedHashMap<String, Integer> report_list = new LinkedHashMap<String, Integer>();
LinkedHashMap<String, Integer> reported_list = new LinkedHashMap<String, Integer>();
for (String s : id_list){
report_list.put(s, 0);
reported_list.put(s, 0);
}
HashSet<String> reportSet = new HashSet<String>(Arrays.asList(report));//Array -> Set 변환
String[] reportArray = reportSet.toArray(new String[0]);//Set -> Array 변환
String[][] reportArray2d = new String[reportArray.length][];
for(int i = 0;i < reportArray.length;i++)
reportArray2d[i] = reportArray[i].split(" ");//스플릿 말고 Startwith도 될것 같았다.
for(String[] s : reportArray2d){
report_list.replace(s[0], report_list.get(s[0]) + 1);
reported_list.replace(s[1], reported_list.get(s[1]) + 1);
}
ArrayList<String> list = new ArrayList<String>();
for(String key : reported_list.keySet()){//k 이상일 경우
if (reported_list.get(key) >= k) list.add(key);
reported_list.replace(key, 0);
}
for(String[] s : reportArray2d){
for(String l : list){
if(s[1].equals(l)){
reported_list.replace(s[0], reported_list.get(s[0]) + 1);
}
}
}
int i = 0;
for(String key : reported_list.keySet()){
answer[i++] = reported_list.get(key);
}
return answer;
}
}
요약
- 1점 밖에 안줬다.
- 별로이거나 내 점수가 높아서 인가.
- 변수를 많이 쓴것 같다. 난잡하다.