Easily understand dp,0ms c++


  • 0
    J
    int climbStairs(int n) {
        if( n < 2 )
            return 1;
        int* m = new int[n+1];
        m[0] = 1;
        m[1] = 1;
        for ( int i = 2; i < n+1; i++ ){
            m[i] = m[i-1] + m[i-2];
        }
        return m[n];
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.