数组中的最长连续子序列python实现:
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# max increasing subsequence
# @param arr int整型一维数组 the array
# @return int整型
#
class Solution:
def MLS(self , arr: List[int]) -> int:
# write code here
nums = set(arr)
res = 0
for i in nums:
if i-1 not in nums:
j = i+1
while j in nums:
j += 1
res = max(res, j-i)
return res