My solution C++ not using any extra space


  • 0
    B
    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[i][j] = min(triangle[i][j]+triangle[i+1][j],triangle[i][j]+triangle[i+1][j+1]);
                }
            }
            return triangle[0][0];
            return 0;
        }
    }

  • 0
    1

    maybe you have noticed that the variable "triangle" is a reference, thus your solution has demolished the original "triangle", I think it is not a good solution.


Log in to reply
 

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