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

数组中的最长连续子序列

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
全部评论

相关推荐

05-26 10:24
门头沟学院 Java
qq乃乃好喝到咩噗茶:其实是对的,线上面试容易被人当野怪刷了
找工作时遇到的神仙HR
点赞 评论 收藏
分享
下个早班:秒挂就是不缺人
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-02 17:58
点赞 评论 收藏
分享
评论
5
1
分享

创作者周榜

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