Untitled

 avatar
unknown
c_cpp
4 years ago
533 B
7
Indexable
int numberOfSteps(int num) {
        //vector<int> minstep;
        int* minstep = new int[num+1];
        minstep[0] = 0;
        
        for(int i = 1; i <= num; i++){
            //cout<<minstep[i-1];
            int de1 = minstep[i-1];
            int d2 = INT_MAX;
            
            if(i%2 == 0){
                d2 = minstep[i/2];
            }
            
            minstep[i] = 1 + min(de1, d2);
        }
        int result = minstep[num];
        delete[] minstep;
        return result;
    }
Editor is loading...