https://school.programmers.co.kr/learn/courses/30/lessons/42584#
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
반복문을 사용해서 풀었다.
조급해하지 말자
class Solution {
public int[] solution(int[] prices) {
int[] answer = new int[prices.length];
for(int i = 0; i < prices.length; i++) {
int cur = prices[i];
int sec = 0;
for(int j = i+1; j < prices.length; j++){
int tmp = prices[j];
sec++;
if(cur > tmp) {
break;
}
}
answer[i] = sec;
}
return answer;
}
}
결과
'Backend > 알고리즘' 카테고리의 다른 글
[프로그래머스] Lv3. 야근 지수 (0) | 2024.05.28 |
---|---|
[프로그래머스]Lv3. 네트워크 (1) | 2024.05.28 |
[프로그래머스] Lv.2 모음 사전 (0) | 2024.05.28 |
[프로그래머스] Lv.2 게임 맵 최단거리 (0) | 2024.05.28 |
[프로그래머스] Lv2. 타겟 넘버 (0) | 2024.05.18 |