(7/18 - X) 문제 풀이하는 데도, 문제를 이해하는 데도 굉장히 오랜 시간이 걸렸다. 바보인가ㅠㅠ
https://school.programmers.co.kr/learn/courses/30/lessons/42584/
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
구현
실수
코드
#include <string>
#include <vector>
#include <stack>
using namespace std;
vector<int> solution(vector<int> prices) {
stack<int> s;
int size = prices.size();
vector<int> answer(size, 0);
for (int i = 0; i < size; i++) {
while (!s.empty()) {
if (prices[i] < prices[s.top()]) {
answer[s.top()] = i - s.top();
s.pop();
}
else {
break;
}
}
s.push(i);
}
while (!s.empty()) {
answer[s.top()] = size - s.top() - 1;
s.pop();
}
return answer;
}
int main() {
solution({ 1,2,3,2,1 });
}
도움 된 글
https://moondol-ai.tistory.com/269
(프로그래머스 스택/큐 문제 풀이) 주식가격
스택/큐(Stack/Queue) 주식가격 문제 설명 초 단위로 기록된 주식가격이 담긴 배열 prices가 매개변수로 주어질 때, 가격이 떨어지지 않은 기간은 몇 초인지를 return 하도록 solution 함수를 완성하세요.
moondol-ai.tistory.com
https://sanghyu.tistory.com/155
[프로그래머스/Python] 주식가격(스택)
코딩테스트 연습 - 주식가격 초 단위로 기록된 주식가격이 담긴 배열 prices가 매개변수로 주어질 때, 가격이 떨어지지 않은 기간은 몇 초인지를 return 하도록 solution 함수를 완성하세요. 제한사항
sanghyu.tistory.com
https://ilmiodiario.tistory.com/119
[프로그래머스] level2. 주식가격 (자바 JAVA)
[ 문제 ] [프로그래머스] level2. 주식가격 (자바 JAVA) 문제 링크 : https://programmers.co.kr/learn/courses/30/lessons/42584 코딩테스트 연습 - 주식가격 초 단위로 기록된 주식가격이 담긴 배열 prices가..
ilmiodiario.tistory.com
https://school.programmers.co.kr/questions/20326
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
'알고리즘 > Programmers' 카테고리의 다른 글
[프로그래머스/C++] 같은 숫자는 싫어 (0) | 2022.07.23 |
---|---|
[프로그래머스/C++] 피로도 (0) | 2022.07.22 |
[프로그래머스/C++] 여행 경로 (0) | 2022.07.16 |
[프로그래머스/C++] 카펫 (0) | 2022.07.16 |
[프로그래머스/C++] 베스트 앨범 (0) | 2022.07.15 |