We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
package main.java.com.poogle.PG.Q42889; import java.util.*; public class Solution { public static int[] solution(int N, int[] stages) { int[] trials = new int[N + 1]; for (int stage : stages) { for (int j = 0; j < stage; j++) { trials[j]++; } } Map<Integer, Double> rates = new HashMap<>(); for (int i = 0; i < N; i++) { if (trials[i] != 0) { rates.put(i + 1, ((trials[i] - trials[i + 1]) / (double) trials[i])); } else { //나누는 수가 0일 때는 0.0으로 넣어줘야 함 rates.put(i + 1, 0.0); } // System.out.println("실패한 사람: " + (trials[i] - trials[i + 1])); // System.out.println("총 도전자: " + (double) trials[i]); // System.out.println("value: " + (trials[i] - trials[i + 1]) / (double) trials[i]); } List<Integer> keySet = new ArrayList<>(rates.keySet()); //value값으로 key 정렬 keySet.sort((val1, val2) -> rates.get(val2).compareTo(rates.get(val1))); return keySet.stream().mapToInt(i -> i).toArray(); } public static void main(String[] args) { System.out.println(Arrays.toString(solution(5, new int[]{2, 1, 2, 4, 2, 4, 3, 3}))); } }
The text was updated successfully, but these errors were encountered:
31d1829
suhyunsim
No branches or pull requests
문제
핵심 아이디어
어려운 점, 실수
풀이
The text was updated successfully, but these errors were encountered: