Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 이런게4문제
- 코딩테스트
- 완전탐색
- find
- KAKAO
- BFS
- 시뮬레이션
- 백준
- 삼성SW역량테스트
- 레벨2
- Sort
- 코딩스킬
- 문자열
- Map
- 삼성
- dfs
- 프로그래머스
- 백트래킹
- STL
- 삼성SW테스트
- 브루트포스
- swea
- priority_queue
- substr
- Set
- dp
- 2018
- C++
- 모의SW역량테스트
- 레벨3
Archives
- Today
- Total
-
[프로그래머스] 레벨 2 - 주식가격 본문
https://programmers.co.kr/learn/courses/30/lessons/42584
코딩테스트 연습 - 주식가격 | 프로그래머스
초 단위로 기록된 주식가격이 담긴 배열 prices가 매개변수로 주어질 때, 가격이 떨어지지 않은 기간은 몇 초인지를 return 하도록 solution 함수를 완성하세요. 제한사항 prices의 각 가격은 1 이상 10,000 이하인 자연수입니다. prices의 길이는 2 이상 100,000 이하입니다. 입출력 예 prices return [1, 2, 3, 2, 3] [4, 3, 1, 1, 0] 입출력 예 설명 1초 시점의 ₩1은 끝까지 가격이 떨어지지
programmers.co.kr
앞의 요소를 잡고 마지막 요소를 고려해 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