不需要额外的空间,时间复杂度O(1/2 * N^2);

class Solution {
public:
    int minimumTotal(vector<vector<int> > &triangle) {
        int n = triangle.size(), ans = 0x7fffffff;

        if(n == 1) return triangle[0][0];
        for(int i = 1; i < n; i++) {
            for(int j = 0; j <= i; j++) {
                if(j == 0) triangle[i][j] += triangle[i-1][j];
                else if(j == i) triangle[i][j] += triangle[i-1][j-1];
                else {
                    triangle[i][j] += min(triangle[i-1][j], triangle[i-1][j-1]);
                }
            }
        }
        for(int j = 0; j < n; j++) 
            ans = min(ans, triangle[n-1][j]);
        return ans;
    } 
};