본문 바로가기
개발/코딩

해커랭크(HackerRank) - Breaking the Records / C++

by lucidmaj7 2020. 2. 3.
728x90
반응형

문제 : 해커랭크 - Breaking the Recods

난이도: Easy

언어 : C++

// Complete the breakingRecords function below.
vector<int> breakingRecords(vector<int> scores) {
    int bestScoreCnt = 0;
    int worstScoreCnt = 0;
    int maxScore = scores.at(0);
    int minScore = scores.at(0);

    vector<int> ret ;

    for(auto iter = scores.begin(); iter!=scores.end();iter++)
    {
        if(*iter>maxScore)
        {
            bestScoreCnt++;
            maxScore= *iter;
        }
        if(*iter<minScore)
        {
            worstScoreCnt++;
            minScore = *iter;
        }
    }
    ret.push_back(bestScoreCnt);
    ret.push_back(worstScoreCnt);
    
    return ret;
}

 

 

728x90
반응형

댓글