티스토리 뷰
반응형
Java
class Solution {
public int[] solution(int[] prices) {
int[] answer = new int[prices.length];
for(int i=0; i<prices.length; i++){
for(int j=i+1; j<prices.length; j++){
if(prices[i] > prices[j]){
// prices[i] = 3, prices[j] = 2 일 경우
// 3에서 2로 가격이 떨어졌지만 1초뒤에 떨어진걸로 간주하여 이것도 1은 증가해준다.
answer[i]++;
break;
}else{
answer[i]++;
}
}
}
return answer;
}
}
이건 문제가 이해하기가 더 어렵네;
반응형
댓글