My slow solution meanwhile is easy to understand.


  • 0
    C

    Suppose the two lines of correct answer is line A and line B. Position of A is in the front of B.
    It is obvious that there is no higher line in the front of A and there is no higher line in the back of line B.

    So, i start from the two lines which are at the middle of the given lines(we can also say given points).

    1. Start at the middle.
    2. Find the highest line in the front half and the highest line in the back half.Suppose is nHighestFrontHalf
      and nHighestBackHalf.
    3. I used two "for" loop, see below:
     for (int i = 0; i < nHighestFrontHalf; i++)
        {
        
             for (int j = nHighestBackHalf - 1; j < vector.size(); j++)
             {
              //  compare and get the max value
              }
        
        }
    
    1. This is very easy to understand but is not fast enough.OK, i admit that it is very slow. Anyway, the code is accepted and somehow it is a solution.

  • 0
    S

    Pay attention to "Writing code? Select all code then click on the {} button to preserve code formatting.” above text editor.


  • 0
    T

    I don't think your code will work if the first half are all very high lines while the second half are all very low lines. In that case, the max area will be formed by two lines in the front half.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.