public int maxProfit(int[] prices) {
if(prices.length<=1) return 0;
int buy=Integer.MAX_VALUE;
int sell=0;
for(int i=0;i<prices.length;i++){
sell=Math.max(sell,prices[i]buy);
buy=Math.min(buy,prices[i]);
}
return sell;
}
Java Simple DP Solutions3ms

@cheng48 I have a stupid question to ask.. but why is it a DP solution? Does DP require an array or something?
Thanks in advance!