https://leetcode.com/problems/best-time-to-buy-and-sell-stock/description/
题目:求数组中两个数差值的最大值
思路:简单dp。
class Solution {
public:
int maxProfit(vector<int>& prices) {
if(prices.empty()) return 0;
int max=0,i=0,len=prices.size();
for(int x=1;x<len;x++)
{
int temp=prices[x]-prices[i];
max=temp>max?temp:max;
if(prices[x]<prices[i]) i=x;
}
return max;
}
};