#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# max increasing subsequence
# @param arr int整型一维数组 the array
# @return int整型
#
class Solution:
def MLS(self , arr: List[int]) -> int:
# write code here
root={}
rs = 1
for i in arr:
if i not in root:
root[i] = [i]
if i-1 in root and i+1 in root:
root[i-1] = root[i-1] + root[i] + root[i+1]
root[i+1] = root[i-1]
root[i] = root[i-1]
elif i-1 in root:
root[i-1] = root[i-1] + root[i]
root[i] = root[i-1]
elif i+1 in root:
root[i+1] = root[i] + root[i+1]
root[i] = root[i+1]
root[root[i][0]] = root[i]
root[root[i][-1]] = root[i]
rs = max(rs, len(set(root[i])))
return rs