题解 | #数组中的最长连续子序列#

数组中的最长连续子序列

http://www.nowcoder.com/practice/eac1c953170243338f941959146ac4bf

数组中的最长连续子序列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
全部评论

相关推荐

点赞 评论 收藏
分享
06-25 16:00
武汉大学 Java
工科研究生底薪工资就开3k啊??
机械打工仔:写文章提成的岗位工资低,你怪工科?
点赞 评论 收藏
分享
评论
5
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务