[Java] 주식가격

Korangii·2024년 7월 19일

프로그래머스

목록 보기
6/21
post-thumbnail

문제 - 주식가격

참고 - 주식가격


lass 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;
	}
}
profile
https://honeypeach.tistory.com/ 로 이전했습니다.

0개의 댓글