mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
0122.买卖股票的最佳时机.md Javascript
This commit is contained in:
@ -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)
|
||||||
|
Reference in New Issue
Block a user