#include <string>
#include <string>
#include <vector>
using namespace std;
vector<int> solution(vector<int> prices)
{
vector<int> answer(prices.size(), 0);
for (int i = 0; i < prices.size(); ++i)
{
for (int j = i + 1; j < prices.size(); ++j)
{
if (prices[i] > prices[j])
{
answer[i] = j - i;
break;
}
else if (j == prices.size() - 1)
answer[i] = j - i;
}
}
return answer;
}
문제 설명이 조금 아쉽다.
1. 주식이 떨어졌을 그 시간의 차이만큼 걸린다.
2. 마지막 주식은 5 - 5 하기 때문에 0
'오늘의 알고리즘' 카테고리의 다른 글
[C++]깊이/너비 우선 탐색(DFS/BFS) 여행경로(프로그래머스 3레벨) (0) | 2022.04.15 |
---|---|
[C++]탐욕법(Greedy) 구명보트(프로그래머스 2레벨) (0) | 2022.04.14 |
[C++]해시 베스트앨범(프로그래머스 3레벨) (0) | 2022.04.12 |
[C++]Summer/Winter Coding(~2018) 영어 끝말잇기(프로그래머스 2레벨) (0) | 2022.04.11 |
[C++]월간 코드 챌린지 시즌1 삼각 달팽이(프로그래머스 2레벨) (0) | 2022.04.09 |