We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 555ea05 commit 8678b9aCopy full SHA for 8678b9a
best-time-to-buy-and-sell-stock/invidam.go
@@ -0,0 +1,12 @@
1
+func maxProfit(prices []int) int {
2
+ maxPriceFrom := make([]int, len(prices)+1)
3
+ for i := len(prices) - 1; i >= 0; i-- {
4
+ maxPriceFrom[i] = max(maxPriceFrom[i+1], prices[i])
5
+ }
6
+
7
+ maxPriceDiff := 0
8
+ for i, price := range prices {
9
+ maxPriceDiff = max(maxPriceDiff, maxPriceFrom[i+1]-price)
10
11
+ return maxPriceDiff
12
+}
0 commit comments