Jingdong - student choir groups

Title: Student a row by row height, several adjacent a group of people, to adjust the ordering within each group only, so that the overall order, find the maximum number of packets

Example: [1,3,2,8,5,6,4,10,7,12,13] 

Output: 5

res = 0
i = 1
mList = [h[0]]
while i<len(h):
    if h[i]>mList[-1]:
        res+=1
        mList.append(h[i])
    else:
        tail = mList[-1]
        while len(mList)>0 and h[i]<mList[-1]:
            mList.pop()
        mList.append(tail)
        res = len(mList)

    i+=1
    # print(mList)
print(res)

  Note:

At that time, when not considered comprehensive written presentation of the results by only 27%, mainly due to not considering the case in the '7'. The main idea is that if the number of the latter is larger than the preceding number, described in the previous section can be set; if less than the number of the foregoing, it and the number in front of a group, there may be several groups smaller than before the front, so determined, is smaller than the current set of most front group, and then the intermediate portion together as a group at this time, the number of variables should be updated to store the first group than the large group.

Guess you like

Origin www.cnblogs.com/kingshine007/p/11407660.html