Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

22.02.21 - [PG] 신고 결과 받기 #218

Closed
suhyunsim opened this issue Feb 21, 2022 · 0 comments
Closed

22.02.21 - [PG] 신고 결과 받기 #218

suhyunsim opened this issue Feb 21, 2022 · 0 comments
Assignees
Labels
lv.1 프로그래머스 - level 1 성공 맞은 문제

Comments

@suhyunsim
Copy link
Owner

문제

핵심 아이디어

  • 통과는 했는데 너무 지저분하게 푼게 아닌가 싶다...!

어려운 점, 실수

풀이

package main.java.com.poogle.PG.Q92334;

import java.util.*;

public class Solution {
    public static void main(String[] args) {
        System.out.println(Arrays.toString(solution(new String[]{"muzi", "frodo", "apeach", "neo"}, new String[]{"muzi frodo", "apeach frodo", "frodo neo", "muzi neo", "apeach muzi"}, 2)));
        System.out.println(Arrays.toString(solution(new String[]{"con", "ryan"}, new String[]{"ryan con", "ryan con", "ryan con", "ryan con"}, 3)));
    }

    private static int[] solution(String[] id_list, String[] report, int k) {
        Set<String> reportSet = new HashSet<>(Arrays.asList(report));
        Map<String, Integer> reportMap = new HashMap<>();
        Map<String, Set<String>> reportList = new HashMap<>();
        Map<String, Integer> result = new HashMap<>();
        for (String id : id_list) {
            reportMap.put(id, 0);
            reportList.put(id, new HashSet<>());
            result.put(id, 0);
        }
        for (String rp : reportSet) {
            String[] list = rp.split(" ");
            reportList.get(list[0]).add(list[1]);
            reportMap.put(list[1], reportMap.get(list[1]) + 1);
        }

        List<String> reportedList = new ArrayList<>();
        for (Map.Entry<String, Integer> entry : reportMap.entrySet()) {
            if (entry.getValue() >= k) {
                reportedList.add(entry.getKey());
            }
        }
        for (Map.Entry<String, Set<String>> entry : reportList.entrySet()) {
            Set<String> findList = entry.getValue();
            for (String s : reportedList) {
                if (findList.contains(s)) {
                    result.put(entry.getKey(), result.get(entry.getKey()) + 1);
                }
            }
        }
        int[] answer = new int[id_list.length];
        for (int i = 0; i < id_list.length; i++) {
            answer[i] = result.get(id_list[i]);
        }
        return answer;
    }
}
@suhyunsim suhyunsim added 성공 맞은 문제 lv.1 프로그래머스 - level 1 labels Feb 21, 2022
@suhyunsim suhyunsim self-assigned this Feb 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lv.1 프로그래머스 - level 1 성공 맞은 문제
Projects
None yet
Development

No branches or pull requests

1 participant