티스토리 뷰

 

#include <iostream>

#include <vector>


using namespace std;

 

vector<int> solution(vector<int> prices) {
      vector<int> answer;
     vector<int>::iterator it1;
     vector<int>::iterator it2;
    

     for(it1=prices.begin(); it1!=prices.end(); it1++) // 각 시점에 대해 실행

    {
        int time=0;

        for(it2=it1+1; it2!=prices.end(); it2++) // 해당 시점 이후에 대해 살펴보기

        {
            //cout << *it1 << " <= " << *it2 << " ?  "; // for debug
            if(*it1 <= *it2) time++; // 해당 시점보다 가격이 떨어지지 않았다면 +1
            else { time++; break; } // 가격이 떨어졌으면 1초간 가격이 떨어지지 않은 것으로 보므로 +1 (문제 조건). 이후 서칭은 종료.
        }
        //cout << time << endl; // for debug
        answer.push_back(time); //정답 벡터에 넣기.
        
     }
    
    return answer;
}

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/05   »
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 28 29 30 31
글 보관함