@@ -54,62 +54,6 @@ Explanation: In this case, no transaction is done, i.e. max profit = 0.
54
54
JS Code:
55
55
56
56
``` js
57
-
58
- /*
59
- * @lc app=leetcode id=122 lang=javascript
60
- *
61
- * [122] Best Time to Buy and Sell Stock II
62
- *
63
- * https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/description/
64
- *
65
- * algorithms
66
- * Easy (50.99%)
67
- * Total Accepted: 315.5K
68
- * Total Submissions: 610.9K
69
- * Testcase Example: '[7,1,5,3,6,4]'
70
- *
71
- * Say you have an array for which the i^th element is the price of a given
72
- * stock on day i.
73
- *
74
- * Design an algorithm to find the maximum profit. You may complete as many
75
- * transactions as you like (i.e., buy one and sell one share of the stock
76
- * multiple times).
77
- *
78
- * Note: You may not engage in multiple transactions at the same time (i.e.,
79
- * you must sell the stock before you buy again).
80
- *
81
- * Example 1:
82
- *
83
- *
84
- * Input: [7,1,5,3,6,4]
85
- * Output: 7
86
- * Explanation: Buy on day 2 (price = 1) and sell on day 3 (price = 5), profit
87
- * = 5-1 = 4.
88
- * Then buy on day 4 (price = 3) and sell on day 5 (price = 6), profit = 6-3 =
89
- * 3.
90
- *
91
- *
92
- * Example 2:
93
- *
94
- *
95
- * Input: [1,2,3,4,5]
96
- * Output: 4
97
- * Explanation: Buy on day 1 (price = 1) and sell on day 5 (price = 5), profit
98
- * = 5-1 = 4.
99
- * Note that you cannot buy on day 1, buy on day 2 and sell them later, as you
100
- * are
101
- * engaging multiple transactions at the same time. You must sell before buying
102
- * again.
103
- *
104
- *
105
- * Example 3:
106
- *
107
- *
108
- * Input: [7,6,4,3,1]
109
- * Output: 0
110
- * Explanation: In this case, no transaction is done, i.e. max profit = 0.
111
- *
112
- */
113
57
/**
114
58
* @param {number[]} prices
115
59
* @return {number}
@@ -137,7 +81,6 @@ class Solution:
137
81
gains = [prices[i] - prices[i- 1 ] for i in range (1 , len (prices))
138
82
if prices[i] - prices[i- 1 ] > 0 ]
139
83
return sum (gains)
140
- print (Solution().maxProfit([7 , 1 , 5 , 3 , 6 , 4 ]))
141
84
# 评论区里都讲这是一道开玩笑的送分题.
142
85
```
143
86
0 commit comments