20220421, 3min
|
```javascript
/**
- @param {number[]} prices
- @return {number} */ // 13:23 -> 13:26 // 贪心:左取最小,右取最大 var maxProfit = function(prices) { let low = Number.MAX_VALUE; let profit = 0; for (let price of prices) { low = Math.min(low, price); profit = Math.max(profit, price - low) } return profit }; ``` | | —- |
20220420, 4min
|
```javascript
// 08:49 -> 08:53
// 贪心,左取最小值,右取最大值
var maxProfit = function(prices) {
let low = Number.MAX_VALUE;
let result = 0;
for (let i = 0; i < prices.length; i++) {
low = Math.min(low, prices[i]);
result = Math.max(result, prices[i] - low)
}
return result;
};
|| --- |<a name="qrXrc"></a>## 20220419, 2min| <br />```javascript// 13:45 -> 13:47//var maxProfit = function(prices) {let low = Number.MAX_VALUE;let result = 0;for (let i = 0; i < prices.length; i++) {low = Math.min(low, prices[i]);result = Math.max(result, prices[i] - low);}return result;};
| | —- |
