var maxProfit = function(prices) {
let ans = 0;
let idx = 0;
let left = idx;
while(idx<prices.length){
let temp = prices[idx] - prices[left];
if(temp>0){
ans = Math.max(ans, temp);
}else{
left = idx;
}
idx++;
}
return ans;
};
121
- 本文链接:http://gulinga.github.io/2022/09/21/arithmetic/LeetCode%E7%83%AD%E9%A2%98HOT100/121/
- 版权声明:本博客所有文章除特别声明外,均默认采用 许可协议。