leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0120.cpp (562B)


      1 class Solution {
      2   public:
      3     int minimumTotal(vector<vector<int>> &triangle) {
      4         int h = triangle.size();
      5 
      6         for (int i = 0; i < h - 1; i++) {
      7             vector<int> vec(i + 2, INT_MAX);
      8             for (int j = 0; j <= i; j++) {
      9                 vec[j] = min(vec[j], triangle[i][j]);
     10                 vec[j + 1] = min(vec[j + 1], triangle[i][j]);
     11             }
     12             for (int j = 0; j <= i + 1; j++)
     13                 triangle[i + 1][j] += vec[j];
     14         }
     15         return *min_element(triangle.back().begin(), triangle.back().end());
     16     }
     17 };