1 class Solution {
 2 public:
 3     int minimumTotal(vector<vector<int> > &triangle) {
 4         // Start typing your C/C++ solution below
 5         // DO NOT write int main() function
 6         int i;
 7         int j;
 8         int t1;
 9         int t2;
10         for(i=triangle.size()-2;i>=0;i--)
11         {
12             for(j=0;j<=i;j++)
13             {
14                 t1=triangle[i][j]+triangle[i+1][j];
15                 t2=triangle[i][j]+triangle[i+1][j+1];
16                 if(t1<t2)
17                 {
18                     triangle[i][j]=t1;
19                 }
20                 else
21                 {
22                     triangle[i][j]=t2; 
23                 }
24             }
25             
26         }
27         return triangle[0][0];
28     }
29 };

 

posted on 2013-06-02 21:28  宇睿  阅读(144)  评论(0编辑  收藏  举报