[프로그래머스] 정수 삼각형
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
int solution(vector<vector<int>> triangle) {
for(int h = 1; h<triangle.size(); ++h){
for(int i = 0; i<triangle[h].size(); ++i){
int maxSum = triangle[h][i];
if(i > 0){
maxSum = max(maxSum, triangle[h][i]+triangle[h-1][i-1]);
}
if(i<triangle[h].size()-1){
maxSum = max(maxSum, triangle[h][i]+triangle[h-1][i]);
};
triangle[h][i] = maxSum;
}
}
int answer = 0;
for(auto it = triangle.back().begin(); it != triangle.back().end(); ++it){
answer = max(answer, *it);
}
return answer;
}