Created
November 5, 2013 15:03
-
-
Save eclipselu/7320370 to your computer and use it in GitHub Desktop.
LeetCode: Triangle http://oj.leetcode.com/problems/triangle/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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