two pointers

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).
     Base * Height > (N-1) * min(a_1, a_N)
  • 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
 
原文地址:https://www.cnblogs.com/chucklu/p/10348787.html