[프로그래머스] [LV2] 주식가격
업데이트:
📚 주식가격
링크📎 : https://programmers.co.kr/learn/courses/30/lessons/42584?language=java
난이도 ⭐️⭐️
📖 문제
📝 내 풀이
import java.util.*;
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++){
answer[i]++;
if(prices[i] > prices[j])
break;
}
}
return answer;
}
}
👊🏻 전략
이중 for문으로 현재 가격보다 떨어지는 지점을 찾아 break~
끝-!
댓글남기기