You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|[Leetcode-3048. Earliest Second To Mark Indices I](https://leetcode.com/problems/earliest-second-to-mark-indices-i/description/)|[python](./leetcode/3048.earliest-second-to-mark-indices-i.py), [c++](./leetcode/3048.earliest-second-to-mark-indices-i.cpp)| O\(M\*logM\)| O\(M\)|\-| - |
196
196
197
197
## Dynamic Programming
198
-
| Problem(27) | Solution | Time | Space | Note | Ref |
198
+
| Problem(28) | Solution | Time | Space | Note | Ref |
|[Leetcode-121. Best Time To Buy And Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/description/)|[c++](./leetcode/121.best-time-to-buy-and-sell-stock.cpp), [python](./leetcode/121.best-time-to-buy-and-sell-stock.py)| O\(N\)| O\(1\)|\-| - |
207
207
|[Leetcode-122. Best Time To Buy And Sell Stock II](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/description/)|[python](./leetcode/122.best-time-to-buy-and-sell-stock-ii.py), [c++](./leetcode/122.best-time-to-buy-and-sell-stock-ii.cpp)| O\(N\)| O\(1\)|\-| - |
208
208
|[Leetcode-139. Word Break](https://leetcode.com/problems/word-break/description/)|[c++](./leetcode/139.word-break.cpp), [python](./leetcode/139.word-break.py)| O\(MN\)| O\(N\)|\-| - |
209
+
|[Leetcode-188. Best Time To Buy And Sell Stock IV](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv/description/)|[python](./leetcode/188.best-time-to-buy-and-sell-stock-iv.py), [c++](./leetcode/188.best-time-to-buy-and-sell-stock-iv.cpp)| O\(NK\)| O\(NK\)|\-| - |
209
210
|[Leetcode-198. House Robber](https://leetcode.com/problems/house-robber/description/)|[c++](./leetcode/198.house-robber.cpp), [python](./leetcode/198.house-robber.py)| O\(N\)| O\(N\)|\-| - |
|[Leetcode-170. Two Sum Iii Data Structure Design](https://leetcode.com/problems/two-sum-iii-data-structure-design/description/)|[python](./leetcode/170.two-sum-iii-data-structure-design.py), [c++](./leetcode/170.two-sum-iii-data-structure-design.cpp)|\-|\-|\-| - |
418
419
|[Leetcode-175. Combine Two Tables](https://leetcode.com/problems/combine-two-tables/description/)|[sql](./leetcode/175.combine-two-tables.sql)|\-|\-|\-| - |
419
-
|[Leetcode-188. Best Time To Buy And Sell Stock IV](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv/description/)|[python](./leetcode/188.best-time-to-buy-and-sell-stock-iv.py), [c++](./leetcode/188.best-time-to-buy-and-sell-stock-iv.cpp)|\-|\-|\-| - |
420
420
|[Leetcode-200. Number Of Islands](https://leetcode.com/problems/number-of-islands/description/)|[c++](./leetcode/200.number-of-islands.cpp), [python](./leetcode/200.number-of-islands.py)|\-|\-|\-| - |
// You are given an integer array prices where prices[i] is the price of a given stock on the ith day, and an integer k.
8
+
// Find the maximum profit you can achieve. You may complete at most k transactions: i.e. you may buy at most k times and sell at most k times.
9
+
// Note: You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).
10
+
//
11
+
// Example 1:
12
+
//
13
+
// Input: k = 2, prices = [2,4,1]
14
+
// Output: 2
15
+
// Explanation: Buy on day 1 (price = 2) and sell on day 2 (price = 4), profit = 4-2 = 2.
16
+
//
17
+
// Example 2:
18
+
//
19
+
// Input: k = 2, prices = [3,2,6,5,0,3]
20
+
// Output: 7
21
+
// Explanation: Buy on day 2 (price = 2) and sell on day 3 (price = 6), profit = 6-2 = 4. Then buy on day 5 (price = 0) and sell on day 6 (price = 3), profit = 3-0 = 3.
# You are given an integer array prices where prices[i] is the price of a given stock on the ith day, and an integer k.
8
+
# Find the maximum profit you can achieve. You may complete at most k transactions: i.e. you may buy at most k times and sell at most k times.
9
+
# Note: You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).
10
+
#
11
+
# Example 1:
12
+
#
13
+
# Input: k = 2, prices = [2,4,1]
14
+
# Output: 2
15
+
# Explanation: Buy on day 1 (price = 2) and sell on day 2 (price = 4), profit = 4-2 = 2.
16
+
#
17
+
# Example 2:
18
+
#
19
+
# Input: k = 2, prices = [3,2,6,5,0,3]
20
+
# Output: 7
21
+
# Explanation: Buy on day 2 (price = 2) and sell on day 3 (price = 6), profit = 6-2 = 4. Then buy on day 5 (price = 0) and sell on day 6 (price = 3), profit = 3-0 = 3.
0 commit comments