就是leetcode的题目:
Best time to sell and buy stock II 的问题。
int maxProfit(vector & prices){
int profit=0;
for(int i=0; i
if(prices[i+1]>prices[i]){
profit += prices[i+1]-prices[i];
}
}
return profit;
}
如果 prices=[], 会有segmentation fault。我用gdb查了下,代码会执行到prices[i
+1]>prices[i]这一行,说明i
就能过
int maxProfit(vector & prices){
int profit=0;
int size=prices.size();
for(int i=0; i
if(prices[i+1]>prices[i]){
profit += prices[i+1]-prices[i];
}
}
return profit;
}
请大家指教。
c**********n 发帖数: 41
2
.size() returns size_t. (size_t)0 - 1 is probably a large positive size_t.