코딩테스트 연습(with java)/프로그래머스
프로그래머스<신고결과>
IT_LEE
2022. 8. 8. 20:02
저번에 다 못푼 문제를 위해 다시 개념서를 읽고 접근하였다.
그래서 생각해낸게 ArrayList를 통해 푸는 방법이다.
꼭 내 손으로 어떻게든 해결해내고 싶다.
복잡한걸 구현하는 문제가 아닌데, 간단히 구현할 로직이 잘 생각이 나지 않는다.
오늘 안에 다 풀고 싶었지만, 시간이 없는 관계로 내일 안에 마무리 지어야겠다.
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
class Solution {
public int[] solution(String[] id_list, String[] report, int k) {
int[] answer = {};
// TreeMap<String,String> map1 = new TreeMap<String,String>();
// for(int i=0; i<report.length; i++){
// String[] foranswer = report[i].split(" ");
// map1.put(foranswer[0], foranswer[1]);
// }
String[] foranswer;
for(int i=0;i<report.length; i++){
String[] foranswer = report[i].split(" ");
}
ArrayList<String> call = new ArrayList<String>();
ArrayList<String> criminal = new ArrayList<String>();
for(int j=0; j<foranswer.length; j++){
if(j%2==0){
call.add(foranswer[j]);
}
else{
criminal.add(foranswer[j]);
}
}
//call = [ muzi, apeach, frodo, muzi, apeach]
//criminal = [frodo, forodo, neo, neo, muzi];
ArrayList<String> al = new ArrayList<String>();
for(int k=0; k<id_list.length; k++){
if(call.contains(id_list[k])=true){
}
}
//procedure
//1. compare 'call' & id_list
//2. get index
//3. count component(pair to index above)
//4. insert into 'al'
return answer;
}
}