腾讯五十题 No.26 买卖股票的最佳时机
作者:互联网
class Solution {
public int maxProfit(int[] prices) {
if(prices.length <= 1)
return 0;
int low = prices[0],res = 0;
for(int i=1;i<prices.length;i++){
low = Math.min(low,prices[i]);
res = Math.max(res,prices[i] - low);
}
return res;
}
}
标签:No.26,int,maxProfit,Solution,最佳时机,腾讯,prices,class 来源: https://www.cnblogs.com/jianjiana/p/15869129.html