leetcode brush questions——


My idea: I misread the title at the beginning. The normal title means: It is known that a column of arrays has 2n numbers, which are paired in pairs, that is, n pairs of numbers. The pairing method is not given, but it is necessary to Maximize the sum of the minimum values ​​among n pairs of numbers, and find the maximum value.

Idea: Arrange the numbers from smallest to largest first
           The first compilation: I thought it was to find the minimum value of the number pair, so I put the largest and the smallest in the sorted array in pairs, then the minimum value of the n number pairs is the sum of the first n numbers. It turned out to be wrong.
           The second time: After re-reading the question, it is found that the maximum value of the required number of pairs is required. Therefore, the number pairs should be connected in pairs in sequence. After writing this time, yes, but it is not coding free, the result is: 71 / 81  test cases passed.

Time complexity: N*N

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325681806&siteId=291194637