Dp,小细节,比较结构要用括号才行如果有其他运算的话,可能优先度不够高
class Solution {public: int minimumTotal(vector<vector<int>>& triangle) { int n = triangle.size(); if(n == 0) return 0; for(int i = n - 1; i >= 1; -- i){ for(int j = 0; j < triangle[i].size() - 1; ++ j){ triangle[i - 1][j] = triangle[i - 1][j] + (triangle[i][j] > triangle[i][j + 1] ? triangle[i][j + 1] : triangle[i][j]); } } return triangle[0][0]; }};新闻热点
疑难解答