티스토리 뷰
programmers.co.kr/learn/courses/30/lessons/42584
1. 문제

2. 풀이
class Solution {
public int[] solution(int[] prices) {
int[] answer = new int[prices.length];
for (int i = 0; i < prices.length; i++) {
boolean isBreak = false;
for (int j = i+1; j < prices.length; j++) {
if (prices[i] > prices[j]) {
answer[i] = j - i;
isBreak = true;
break;
}
}
if (!isBreak) {
answer[i] = prices.length - 1 - i;
}
}
return answer;
}
}
이중 for문을 이용해서 i번째부터 i+1을 시작으로 끝까지 체크하면서 i번째값과 비교해서 작은 경우 answer 배열에 j-i를 넣어주고 break하도록 처리함.
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- Synchronous
- 블로킹
- 프로그래머스 Level 1
- 해시
- 인터셉터
- 필터
- Filter
- a
- blocking
- 프로그래머스
- Asynchronous
- 동기
- Handler Interceptor
- 비동기
- http://www.nextree.co.kr/p6960/
- 핸들러 인터셉터
- 프로그래머스 Level 3
- 프로그래머스 Level 2
- non-blocking
- 코딩테스트 고득점 Kit
- 논블로킹
- 스택/큐
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
글 보관함