题目思路
健身回来再写 哈哈 反正没人看我的博客- 代码:
class Solution { public: int minimumTotal(vector<vector<int>>& triangle) { int row = triangle.size(); int col = triangle[row - 1].size(); vector<vector<int>> dp(row,vector<int>(col)); for (int i = 0; i < col; ++i) { dp[row - 1][i] = triangle[row - 1][i]; } for (int i = row - 2; i >= 0; i--) { for (int j = 0; j < triangle[i].size(); j++) { dp[i][j] = std::min(dp[i + 1][j], dp[i + 1][j + 1]) + triangle[i][j]; } } return dp[0][0]; } };
- 参考资料
1 https://www.cnblogs.com/mozi-song/p/9626067.html 《120. Triangle》
2 https://leetcode.com/problems/triangle/discuss/38730/DP-Solution-for-Triangle 《DP Solution for Triangle》