Skip to content

Commit 395bdd7

Browse files
committed
0122.买卖股票的最佳时机.md Javascript
1 parent 7d15e7e commit 395bdd7

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

problems/0122.买卖股票的最佳时机II.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,17 @@ class Solution:
190190
Go:
191191

192192

193-
193+
Javascript:
194+
```Javascript
195+
// 贪心
196+
var maxProfit = function(prices) {
197+
let result = 0
198+
for(let i = 1; i < prices.length; i++) {
199+
result += Math.max(prices[i] - prices[i - 1], 0)
200+
}
201+
return result
202+
};
203+
```
194204

195205
-----------------------
196206
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)

0 commit comments

Comments
 (0)