动规动规
class Solution {
public int maxProfit(int[] prices) {
if(prices.length == 0) return 0;
int[] f = new int[prices.length+1];
f[0] = 0;
int maxp = 0;
int mixp = prices[0];
for(int i=1; i<prices.length; i++){
mixp = Math.min(mixp,prices[i]);
if(prices[i] - mixp <= 0) f[i] = 0;
else f[i] = prices[i] - mixp;
maxp = Math.max(f[i],maxp);
}
return maxp;
}
}