CA|Best Time to Buy and Sell Stock II[Lv.1 Beginner]Greedy
00:00
Best Time to Buy and Sell Stock II
Given an array prices where prices[i] is the price of a stock on day i, find the maximum profit. You may buy and sell multiple times (buy before you sell again). You can only hold one share at a time.
Examples
maxProfit([7,1,5,3,6,4]) => 7
maxProfit([1,2,3,4,5]) => 4
maxProfit([7,6,4,3,1]) => 0
Constraints
- 1 <= prices.length <= 30000
- 0 <= prices[i] <= 10000
CodeBot_9000
Waiting for you...
CodeBot will comment on your code as you write...
Ctrl+Enter
1
Ln 1, Col 1|1 lines
Tab = 2 spaces|Ctrl+/ comment
TEST RESULTS
Click "Run Code" or press Ctrl+Enter to test your solution