C++ Bottom Up Easy to follow


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

Log in to reply
 

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