提交代码
class Solution {
public int maxProfit(int[] prices) {
if(prices==null||prices.length==0) return 0;
int res=0,in=prices[0],out=prices[0];
for(Integer price:prices) {
if(price<in) {
in=price;
out=0;
}
else if(price>out) out=price;
res=out-in>res?out-in:res;
}
return res;
}
}
运行结果
来源:CSDN
作者:AXIMI
链接:https://blog.csdn.net/AXIMI/article/details/104533084