-
스택/큐 > 주식가격프로그래머스(Programmers) 2018. 9. 26. 21:47반응형
https://programmers.co.kr/learn/courses/30/lessons/42584
1. 문제
2. 알고리즘
키워드 - 구현
3. 코드
12345678910111213141516171819202122232425262728293031323334// 그지 같은 풀이#include <string>#include <vector>using namespace std;vector<int> solution(vector<int> prices) {vector<int> answer;const int size = prices.size();for (int i = 0; i < size; i++) {int cand = prices[i];int second = 0;bool down = false;for (int j = i; j < size; j++) {if (cand > prices[j]) {down = true;break;}second++;}if (down)answer.push_back(second);else if (down == false && second) {answer.push_back(second - 1);} else {answer.push_back(0);}}return answer;}cs 12345678910111213141516171819202122232425#include <string>#include <vector>using namespace std;vector<int> solution(vector<int> prices) {vector<int> answer;const int size = prices.size();for (int i = 0; i < size; i++) {int cand = prices[i];int second = 0;for (int j = i; j < size-1; j++) {if (cand <= prices[j]) {second++;} else {break;}}answer.push_back(second);}return answer;}cs 반응형'프로그래머스(Programmers)' 카테고리의 다른 글
정렬 > H-Index (0) 2018.09.30 해시 > 전화번호 목록 (0) 2018.09.30 스택/큐 > 쇠막대기 (0) 2018.09.26 스택/큐 > 탑 (0) 2018.09.26 정렬 > 가장 큰 수 (0) 2018.09.20