https://programmers.co.kr/learn/courses/30/lessons/42584?language=cpp
코딩테스트 연습 - 주식가격
초 단위로 기록된 주식가격이 담긴 배열 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
23
24
25
26
27
|
#include <string>
#include <vector>
using namespace std;
vector<int> solution(vector<int> prices) {
vector<int> answer;
for (int i = 0; i < prices.size()-1; i++)
{
int count = 0;
for (int j = i + 1; j < prices.size(); j++)
{
if (prices[i] <= prices[j]) //값이 떨어지지 않았으면 시간++
{
count++;
}
else //떨어졌다면 시간++ 하고 for문을 빠져나온다.
{
count++;
break;
}
}
answer.push_back(count);
}
return answer;
}
|
'프로그래머스 - 내 풀이 > 프로그래머스 Lv2' 카테고리의 다른 글
프로그래머스 / Summer/Winter Coding(~2018) / 영어 끝말 잇기 (0) | 2020.09.08 |
---|---|
프로그래머스 / Summer,Winter Coding(2019) / 멀쩡한 사각형 (0) | 2020.07.17 |
프로그래머스 / 스택, 큐 / 프린터 (0) | 2020.06.18 |
프로그래머스 / 연습문제 / 124 나라의 숫자 (0) | 2020.06.17 |
프로그래머스 / 스택,큐 / 탑 (0) | 2020.06.16 |