class Solution {
public:
int minimumTotal(vector<vector<int>>& triangle) {
if(triangle.size() == ) return triangle[][];
triangle[][] += triangle[][];triangle[][] += triangle[][];
if(triangle.size() == ) return min(triangle[][],triangle[][]);
int a = min(triangle[][],triangle[][]);
for(int i=;i < ;i++){
triangle[][i] += a;
}
triangle[][] += triangle[][];
for(int i=;i < triangle.size();i++){
triangle[i][] += min(triangle[i-][],triangle[i-][]);
for(int j=;j < triangle[i].size()-;j++){
int x = min(triangle[i-][j-],triangle[i-][j]);
int y = min(x,triangle[i-][j+]);
triangle[i][j] += y;
}
triangle[i][triangle[i].size()-] += min(triangle[i-][triangle[i].size()-],triangle[i-][triangle[i].size()-]);
triangle[i][triangle[i].size()-] += triangle[i-][triangle[i].size()-];
}
return findmin(triangle[triangle.size()-]);
}
int findmin(vector<int> temp){
int minnum = temp[];
for(int i=;i < temp.size();i++){
if(minnum > temp[i]) minnum = temp[i];
}
return minnum;
}
};
——题意没写清楚,相邻是左中右还是中右,WA了一发
class Solution {
public:
int minimumTotal(vector<vector<int>>& triangle) {
if(triangle.size() == ) return triangle[][];
triangle[][] += triangle[][];triangle[][] += triangle[][];
for(int i=;i < triangle.size();i++){
triangle[i][] += triangle[i-][];
for(int j=;j < triangle[i].size()-;j++){
triangle[i][j] += min(triangle[i-][j-],triangle[i-][j]);
}
triangle[i][triangle[i].size()-] += triangle[i-][triangle[i].size()-];
}
return findmin(triangle[triangle.size()-]);
}
int findmin(vector<int> temp){
int minnum = temp[];
for(int i=;i < temp.size();i++){
if(minnum > temp[i]) minnum = temp[i];
}
return minnum;
}
};
_