Super simple code, easy to understand


  • 0
    Y

    class Solution {
    public:

    int minimumTotal(vector<vector<int>>& triangle) {
       int n = triangle.size();
       //0 ~ n -1
       if(n == 0)
            return 0;
       if(n == 1)
            return triangle[0][0];
        
       for(int i = n -2; i >= 0; i --)
       {
           for(int k = 0; k <= i; k ++)
                triangle[i][k] += std::min(triangle[i + 1][k], triangle[i + 1][k + 1]);
       }
       
       return triangle[0][0];
    }
    

    };


Log in to reply
 

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