Triangle

题目如下:

我的思路是从上往下沉淀。

int minimumTotal(vector<vector<int>>& triangle)
{
    for (int i = 1; i != triangle.size(); ++i){
        auto& lastRow    = triangle[i - 1];
        auto& currentRow = triangle[i];
        
        currentRow[0]    += lastRow[0];
        currentRow[i]    += lastRow[i - 1];
        
        for (int j = 1; j != i; ++j){
            currentRow[j] += min(lastRow[j - 1], lastRow[j]);
        }
    }
    return *min_element(triangle.back().cbegin(),
                        triangle.back().cend());
}
原文地址:https://www.cnblogs.com/wuOverflow/p/5055155.html