Advertisement
lazar955

Untitled

Oct 22nd, 2023
1,183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.45 KB | None | 0 0
  1. func maxArea(height []int) int {
  2.     res :=0
  3.  
  4.     l,r:=0,len(height)-1
  5.  
  6.     for l<r {
  7.         area:= (r-l) * min(height[l],height[r])
  8.         res = max(res,area)
  9.         if height[l] < height[r] {
  10.             l++
  11.         }else {
  12.             r--
  13.         }
  14.     }
  15.     return res
  16. }
  17.  
  18. func min(r,l int) int {
  19.     if r < l {
  20.         return r
  21.     }
  22.     return l
  23. }
  24. func max(r,l int) int {
  25.     if r > l {
  26.         return r
  27.     }
  28.     return l
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement