[Programmers] 주식가격
문제 바로가기 : https://programmers.co.kr/learn/courses/30/lessons/42584
SolutionPermalink
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <vector> | |
#include <stack> | |
using namespace std; | |
vector<int> solution(vector<int> prices) { | |
vector<int> answer; | |
for(int i=0; i<prices.size(); i++){ | |
int cnt=0; | |
for(int j=i+1; j<prices.size(); j++){ | |
if(prices[i] <= prices[j]) cnt++; | |
else{ | |
cnt++; | |
break; | |
} | |
} | |
answer.push_back(cnt); | |
} | |
return answer; | |
} |
reviewPermalink
스택/큐 문제로 분류가 돼있었지만 이중 for문이 제일 간단해보여서 작성해보고 통과했다.
누가봐도 O(n^2)여서 효율성 테스트에서 통과하지 못할거 같았는데 통과돼서 좀 놀랐다..
댓글남기기