일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Kubernetes
- K8S
- Code Jam
- 하늘과 바람과 별과 詩
- ESXi 업데이트
- on-prem
- swift
- Code Jam 2022
- secondlowestgrade
- 파이썬
- 3D PRINTING
- 2022
- 코딩테스트
- 방통대 대학원 정보과학과
- ingress-nginx
- 하늘과 바람과 별과 시
- LEVEL 2
- 정보과학과
- 방송통신대학교 대학원 정보과학과
- Python
- C++
- MySQL
- 프로그래머스
- openebs
- nestedlists
- GitLab
- hackerrank
- Qualification Round
- 해커랭크
Archives
- Today
- Total
공대생의 비망록
[프로그래머스][Lv. 2] 주식가격 C++ 풀이 본문
https://programmers.co.kr/learn/courses/30/lessons/42584
코딩테스트 연습 - 주식가격
초 단위로 기록된 주식가격이 담긴 배열 prices가 매개변수로 주어질 때, 가격이 떨어지지 않은 기간은 몇 초인지를 return 하도록 solution 함수를 완성하세요. 제한사항 prices의 각 가격은 1 이상 10,00
programmers.co.kr
풀이는 추후에 차차 올리도록 하겠습니다...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#include <string>
#include <vector>
using namespace std;
vector<int> solution(vector<int> prices) {
vector<int> answer;
int size = prices.size();
for (int i = 0; i < size; i++) {
int prevPrice = prices[i], seconds = -1;
for (int j = i; j < size; j++) {
seconds++;
if (prevPrice > prices[j]) {
break;
}
}
answer.push_back(seconds);
}
return answer;
}
|
cs |
'Programming Language > C, C++' 카테고리의 다른 글
[프로그래머스][Lv. 2] 가장 큰 수 C++ 풀이 (0) | 2022.05.17 |
---|---|
[프로그래머스][Lv. 2] 위장 C++ 풀이 (0) | 2022.05.17 |
[프로그래머스][Lv. 2] 행렬의 곱셈 C++ 풀이 (0) | 2022.05.03 |
[프로그래머스][Lv. 2] 카카오프렌즈 컬러링북 C++ 풀이 (0) | 2022.05.03 |
[C++] map 컨테이너에 데이터 추가하기 insert()? [] 연산자? (0) | 2022.05.03 |
Comments