Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func maxProfit(prices []int) int {
- l,r:=0,1 // buy, sell
- maxP:=0
- for r < len(prices) {
- if prices[l] < prices[r] {
- profit := prices[r] - prices[l]
- maxP = max(maxP, profit)
- }else {
- l = r
- }
- r +=1
- }
- return maxP
- }
- func max(l,r int )int {
- if l > r {
- return l
- }
- return r
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement