C++ bottom up no extra space needed.


  • 0
    H
    class Solution {
    public:
        int minimumTotal(vector<vector<int>>& triangle) {
    
            for (int idx = triangle.size()-1; idx > 0; idx--)
            {
                for (int idx1 = 0; idx1 < idx; idx1++)
                {
                    triangle[idx -1][idx1] += min(triangle[idx][idx1],triangle[idx][idx1+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.