1. 程式人生 > >two pointers

two pointers

reat point star for get same fin sam quick

https://www.geeksforgeeks.org/container-with-most-water/

Approach :

  • This implies that if there was a better solution possible, it will definitely have the Height greater than min(a1, aN).
    技術分享圖片
  • We know that, Base min(a1, aN)
    This means that we can discard min(a1, aN) from our set and look to solve this problem again from the start.
  • If a1 < aN, then the problem reduces to solving the same thing for a2, aN.
  • Else, it reduces to solving the same thing for a1, aN-1

two pointers