Notice
Recent Posts
Recent Comments
-
[프로그래머스] 레벨 2 - 주식가격 본문
https://programmers.co.kr/learn/courses/30/lessons/42584
앞의 요소를 잡고 마지막 요소를 고려해 0을 푸시백해준 뒤, 인덱스 변수에 대한 값의 증감 다음 조건을 확인해주면 바로 뒤의 작아지는 요소에 대응할 수 있다. 간단한 문제.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
#include <string>
#include <vector>
using namespace std;
vector<int> solution(vector<int> prices) {
vector<int> answer;
int idx = 0;
for(int i=0; i<prices.size(); i++){
answer.push_back(0);
int cur = prices[i];
for(int j=i+1; j<prices.size(); j++){
answer[idx]++;
if(prices[j] < cur) break;
}
idx++;
}
return answer;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs |
'1-4. 프로그래머스' 카테고리의 다른 글
[프로그래머스] 레벨 2 - 더 맵게 (0) | 2020.02.06 |
---|---|
[프로그래머스] 레벨 2 - 가장 큰 수 (0) | 2020.02.04 |
[프로그래머스] 레벨 2 - 다리를 지나는 트럭 (0) | 2020.02.03 |
[프로그래머스] 레벨 2 - 기능개발 (0) | 2020.02.03 |
[프로그래머스] 레벨 2 - 프린터 (0) | 2020.02.03 |
Comments