Skip to content

Instantly share code, notes, and snippets.

@eclipselu
Created November 5, 2013 15:03
Show Gist options
  • Save eclipselu/7320370 to your computer and use it in GitHub Desktop.
Save eclipselu/7320370 to your computer and use it in GitHub Desktop.
class Solution {
public:
int minimumTotal(vector<vector<int> > &triangle) {
// IMPORTANT: Please reset any member data you declared, as
// the same Solution instance will be reused for each test case.
if (triangle.empty())
return 0;
int m = triangle.size();
for (int i = m - 2; i >= 0; i--)
for (int j = 0; j < triangle[i].size(); j++)
triangle[i][j] += min(triangle[i + 1][j], triangle[i + 1][j + 1]);
return triangle[0][0];
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment