4-line in-place c++ solution


  • 1
    M
    class Solution {
    public:
        int minimumTotal(vector<vector<int>>& triangle) {
            for (int i=triangle.size()-2; i>=0; i--)
                for (int j=0; j<triangle[i].size(); j++)
                    triangle[triangle.size()-1][j] = triangle[i][j] + min(triangle[triangle.size()-1][j], triangle[triangle.size()-1][j+1]);
            return triangle[triangle.size()-1][0];
        }
    };

Log in to reply
 

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