大家度假用什么timer控制电灯开关阿?# Living
i*t
1 楼
自己编辑可以通过啊 放在leetcode 说time error。。。
咋回事啊
class Solution {
public:
int minimumTotal(vector > &triangle) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int minV = INT_MAX;
int m = triangle.size();
vector > vecV;
vecV.resize(m);
if(m==0) return 0;
if(m==1) return triangle[0][0];
vecV[0][0]=triangle[0][0];
for(int i=1;i {
int n = triangle[i].size();
vecV[i].resize(n);
for(int j=0;j {
vecV[i][j] =INT_MAX;
int leftIdx = j-1;
int middleIdx = j;
int rightIdx = j+1;
if(leftIdx>=0 && leftIdx {
vecV[i][j]=min(vecV[i][j], vecV[i-1][leftIdx]+triangle[i
][j] );
}
if(middleIdx>=0 && middleIdx {
vecV[i][j]= min( vecV[i][j], vecV[i-1][middleIdx]+
triangle[i][j] ) ;
}
if(rightIdx>=0 && rightIdx {
vecV[i][j]= min( vecV[i][j], vecV[i-1][rightIdx]+
triangle[i][j] ) ;
}
}
}
vector v;
for(int j=0;j {
v.push_back( vecV[m-1][j]);
}
std::sort(v.begin(),v.end());
return v[0];
}
};
咋回事啊
class Solution {
public:
int minimumTotal(vector
// Start typing your C/C++ solution below
// DO NOT write int main() function
int minV = INT_MAX;
int m = triangle.size();
vector
vecV.resize(m);
if(m==0) return 0;
if(m==1) return triangle[0][0];
vecV[0][0]=triangle[0][0];
for(int i=1;i
int n = triangle[i].size();
vecV[i].resize(n);
for(int j=0;j
vecV[i][j] =INT_MAX;
int leftIdx = j-1;
int middleIdx = j;
int rightIdx = j+1;
if(leftIdx>=0 && leftIdx
vecV[i][j]=min(vecV[i][j], vecV[i-1][leftIdx]+triangle[i
][j] );
}
if(middleIdx>=0 && middleIdx
vecV[i][j]= min( vecV[i][j], vecV[i-1][middleIdx]+
triangle[i][j] ) ;
}
if(rightIdx>=0 && rightIdx
vecV[i][j]= min( vecV[i][j], vecV[i-1][rightIdx]+
triangle[i][j] ) ;
}
}
}
vector
for(int j=0;j
v.push_back( vecV[m-1][j]);
}
std::sort(v.begin(),v.end());
return v[0];
}
};