121. 买卖股票的最佳时机
class Solution {
public:
int maxProfit(vector<int>& prices) {
int counter=0;int ans=0;
for(int i=1;i<prices.size();i++)
{
counter+=prices[i]-prices[i-1];
if(counter<0)
{
counter=0;
}
ans=max(counter,ans);
}
return ans;
}
};