Untitled

mail@pastecode.io avatar
unknown
c_cpp
3 years ago
453 B
3
Indexable
Never
 int numberOfSteps(int num) {
        vector<int> minstep;
        
        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);
        }
        
        return minstep[num];
    }