public class Solution {
public int maxProfit(int[] prices) {
if(prices.length==0) return 0;
int max=0,minprice=prices[0];
for(int i=1;i<prices.length;i++){
if(prices[i]>minprice){
max=Math.max(max,prices[i]-minprice);
}else minprice=prices[i];
}
return max;
}
}
网友评论