My clean way solve this using c++


  • 0
    T
    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());
    }

Log in to reply
 

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