문제
https://school.programmers.co.kr/learn/courses/30/lessons/42889
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
코드
import java.util.*;
class Solution {
public int[] solution(int N, int[] stages) {
List<Info> list = new ArrayList<>();
for(int i=0;i<N;i++){
int total = 0;
int fail = 0;
for(int j=0;j<stages.length;j++){
if(stages[j] - 1 >= i){
total++;
if(stages[j] - 1 == i) fail++;
}
}
if(total == 0) list.add(new Info(i+1, 0));
else list.add(new Info(i+1, (double)fail/total));
}
Collections.sort(list, (o1, o2)-> Double.compare(o2.rate, o1.rate));
int answer [] = new int [N];
for(int i=0;i<N;i++){
answer[i] = list.get(i).stage;
}
return answer;
}
}
class Info {
int stage;
double rate;
Info(int stage, double rate){
this.stage = stage;
this.rate = rate;
}
}
문제
https://school.programmers.co.kr/learn/courses/30/lessons/42889
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
코드
import java.util.*; class Solution { public int[] solution(int N, int[] stages) { List<Info> list = new ArrayList<>(); for(int i=0;i<N;i++){ int total = 0; int fail = 0; for(int j=0;j<stages.length;j++){ if(stages[j] - 1 >= i){ total++; if(stages[j] - 1 == i) fail++; } } if(total == 0) list.add(new Info(i+1, 0)); else list.add(new Info(i+1, (double)fail/total)); } Collections.sort(list, (o1, o2)-> Double.compare(o2.rate, o1.rate)); int answer [] = new int [N]; for(int i=0;i<N;i++){ answer[i] = list.get(i).stage; } return answer; } } class Info { int stage; double rate; Info(int stage, double rate){ this.stage = stage; this.rate = rate; } }