본문 바로가기
개발/코딩

해커랭크(HackerRank) - Running Time of Algorithms / C++

by lucidmaj7 2020. 7. 11.
728x90
반응형

문제 : 해커랭크 

Running Time of Algorithms

www.hackerrank.com/challenges/runningtime/problem?h_r=next-challenge&h_v=zen

 

Running Time of Algorithms | HackerRank

The running time of Algorithms in general and Insertion Sort in particular.

www.hackerrank.com

 

난이도 : easy

// Complete the runningTime function below.
int runningTime(vector<int> arr) {

    int shfitCout = 0;
    for(int i = 1 ; i<arr.size(); i++)
    {
        int value = arr[i];
        int j = i -1;
        while(j>= 0 && arr[j]>value)
        {
            arr[j+1] = arr[j];
            j--;
            shfitCout++;
        }
        arr[j+1] = value;
    }

    return shfitCout;

}

728x90
반응형

댓글