Skip to content

Commit

Permalink
Create 122-Best-Time-to-Buy-and-Sell-Stock-II.go
Browse files Browse the repository at this point in the history
  • Loading branch information
razer96 committed Dec 22, 2022
1 parent 85918f7 commit 8c07a45
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions go/122-Best-Time-to-Buy-and-Sell-Stock-II.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
func maxProfit(prices []int) int {
var maxProfit int

for i := 0; i < len(prices) - 1; i++ {
if prices[i] < prices[i+1] {
maxProfit += prices[i+1] - prices[i]
}
}

return maxProfit
}

0 comments on commit 8c07a45

Please sign in to comment.