My solution without extra space


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

  • 0
    L

    good solution


  • 0
    G

    seems like a good solution. But, you changed the orginal triangle


Log in to reply
 

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