Skip to content

Commit

Permalink
Merge pull request #872 from bus710/week05
Browse files Browse the repository at this point in the history
[bus710] week 05
  • Loading branch information
bus710 authored Jan 9, 2025
2 parents d4b8b1f + 6906deb commit 8140869
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions best-time-to-buy-and-sell-stock/bus710.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// https://leetcode.com/problems/best-time-to-buy-and-sell-stock/

package hello

func maxProfit(prices []int) int {
min := prices[0]
maxProfit := 0

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

return maxProfit
}

0 comments on commit 8140869

Please sign in to comment.