Shortest solution using top down approach


#1

Comment body goes here.
int Solution::minimumTotal(vector<vector > &A) {

int n = A.size();
for(int i = n-2; i >=0; i--){
    for(int j = 0; j < A[i].size(); j++){
        A[i][j] = A[i][j] + min(A[i+1][j],A[i+1][j+1]); 
    }
}
return A[0][0];

}


#2

thanks for solution but how can we approach to these type of problems


#3

well its simple you know.
Start thinking from base case only.
If you had only 1 row then that would have been your answer.
If you had 2 rows then in first row there will be only 1 element and in 2nd row 2 elements. And for first row element it has to pick the minimum out of two.
Similarly u can extend this thinking for n rows.