0122.买卖股票的最佳时机.md Javascript
This commit is contained in:
parent
7d15e7e852
commit
395bdd7509
|
|
@ -190,7 +190,17 @@ class Solution:
|
||||||
Go:
|
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)
|
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue