코딩테스트
[프로그래머스] 주식가격
gajy
2022. 6. 10. 02:57
728x90
https://programmers.co.kr/learn/courses/30/lessons/42584?language=java
[나의 답]
import java.util.*;
import java.util.stream.Collectors;
class Solution {
public int[] solution(int[] prices) {
int[] answer = new int[prices.length];
List<Integer> priceList = Arrays.stream(prices)
.boxed()
.collect(Collectors.toList());
for(int i = 0; i < prices.length-1; i++) {
answer[i] = count(prices[i], priceList.subList(i+1, prices.length));
}
answer[priceList.size()-1] = 0;
return answer;
}
public int count(int price, List<Integer> priceList) {
int count = 0;
for(int p : priceList) {
if(price <= p) {
count ++;
}else{
return ++count;
}
}
return count;
}
}
728x90