Merge pull request #269 from fusunx/master

0122.买卖股票的最佳时机.md Javascript
This commit is contained in:
Carl Sun 2021-05-27 15:36:37 +08:00 committed by GitHub
commit 4a179ca0bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 1 deletions

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)