0122.买卖股票的最佳时机.md Javascript

This commit is contained in:
fusunx
2021-05-27 08:10:25 +08:00
parent 7d15e7e852
commit 395bdd7509

View File

@ -190,7 +190,17 @@ class Solution:
Go
Javascript:
```Javascript
// 贪心
var maxProfit = function(prices) {
let result = 0
for(let i = 1; i < prices.length; i++) {
result += Math.max(prices[i] - prices[i - 1], 0)
}
return result
};
```
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)