문제

programmers 주식가격 문제 보러가기



풀이

class Solution {
	public int[] solution(int[] prices) {
		int[] answer = new int[prices.length];

		for (int i = 0; i < prices.length; i++) {
			int price = prices[i];
			for (int j = i + 1; j < prices.length; j++) {
				if (price > prices[j] || j == answer.length - 1) {
					answer[i] = j-i;
					break;
				}
			}
		}
		return answer;
	}
}



문제점 해결

스택/큐를 사용해서 푸는 문제라고 생각했지만 이중 for문으로 해결 할 수 있는 문제였다.