但是如果把while (i < (prices.size() - 1)) 改成两行 int k = (prices.size() -
1); while (i < k)就没有问题编译器的问题吗
int maxProfit(vector &prices) {
int sum = 0;
int i = 0;
while (i < (prices.size() - 1))
{
if (prices[i] < prices[i + 1])
{
sum += prices[i + 1] - prices[i];
}
++i;
}
return sum;
}
int _tmain(int argc, _TCHAR* argv[])
{
int a = maxProfit(vector());
return 0;
}