leetcode120

每次判断当前元素上面和斜左上角的元素即可。

class Solution {
public:
    int minimumTotal(vector>& triangle) {
        int Max = INT_MAX;
        for(int i = 0;i=0 && j-1 < triangle[i-1].size()) t1 = triangle[i-1][j-1];
                    if(i-1>=0 && j < triangle[i-1].size()) t2 = triangle[i-1][j];
                    triangle[i][j]+=min(t1,t2); 
                }
                
                if(i == triangle.size()-1) Max = min(Max,triangle[i][j]);
            }
        }
        
        return Max;
    }
};

 

你可能感兴趣的:(leetcode)