Priority Queue yyds
#
# max increasing subsequence
# @param arr int整型一维数组 the array
# @return int整型
#
import heapq
class Solution:
def MLS(self , arr ):
eleCount = len(arr)
heapq.heapify(arr)
count = 1
maxCount = 1
lastPop = heapq.heappop(arr)
for _ in range(eleCount - 1):
cur = heapq.heappop(arr)
if cur == lastPop + 1:
count += 1
if count > maxCount:
maxCount = count
elif cur == lastPop:
continue
else:
count = 1
lastPop = cur
return maxCount