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 4f5c769 commit a4e6944Copy full SHA for a4e6944
best-time-to-buy-and-sell-stock/yhkee0404.go
@@ -0,0 +1,9 @@
1
+func maxProfit(prices []int) int {
2
+ ans := 0
3
+ bought := prices[0]
4
+ for i := 1; i != len(prices); i++ {
5
+ ans = max(ans, prices[i] - bought)
6
+ bought = min(bought, prices[i])
7
+ }
8
+ return ans
9
+}
0 commit comments