题解 | #最小三角路径和#
最小三角路径和
https://www.nowcoder.com/practice/cc6afb95517f460cb785397c36ae4a9b
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param cows int整型vector<vector<>> * @return int整型 */ int minimumTotal(vector<vector<int> >& cows) { // write code here int result = cows[0][0]; int y = 0; for (int i = 1;i < cows.size();++i) { int x = i; int temp = 0; if (cows[x][y] < cows[x][y + 1]) { result += cows[x][y]; } else { result += cows[x][y + 1]; y += 1; } } return result; } };
模拟