Aerial Movie(双指针,2sum)
Description
In order to prevent passengers from being too bored during the flight, LQ Airlines decided to play two movies during the flight. Since the movie cannot be played during the take-off and landing of the aircraft, LQ Airlines must ensure that theduration of the two movies
to be less than or equal tothe flight duration minus 30 minutes
, and the total length of the two movies should be as long as possible. Now givent
,the flight duration(minutes), and arraydur[]
,the length of movies. Please output the length of the two movies in order of length. If there are multiple groups of the same length, select the one which contains the longest single moive.It is guarantee that there is a least one solution.
30<t<=1000 dur[i]<=1000 1<=len(dur)<=100000
Have you met this question in a real interview?
Yes
Problem Correction
Example
Givent=87
,dur=[20,25,19,37]
,return[20,37]
Givent=67
,dur=[20,17,19,18]
,return[17,20]
分析
双指针 two sum closest,记得要sort
Last updated