Skip to content

Commit 06bec06

Browse files
committed
feat: add question 122
1 parent 3e62d04 commit 06bec06

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

122.买卖股票的最佳时机-ii.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* @lc app=leetcode.cn id=122 lang=javascript
3+
*
4+
* [122] 买卖股票的最佳时机 II
5+
*
6+
* 1. 只要比前一天价格低, 就有差值可以赚
7+
*/
8+
9+
// @lc code=start
10+
/**
11+
* @param {number[]} prices
12+
* @return {number}
13+
*/
14+
var maxProfit = function(prices) {
15+
let result = 0;
16+
for (let i = 1; i < prices.length; i++) {
17+
if (prices[i] > prices[i - 1]) {
18+
result += prices[i] - prices[i - 1];
19+
}
20+
}
21+
return result;
22+
};
23+
// @lc code=end
24+

0 commit comments

Comments
 (0)