题解 | #在字符串中找出连续最长的数字串#比滑窗简单

在字符串中找出连续最长的数字串

http://www.nowcoder.com/practice/2c81f88ecd5a4cc395b5308a99afbbec

while 1:
    try:
        s = input()
        l, m = 0, 0
        n = s.__len__()
        temp = ''
        res = ''
        while l < n:
            c = s[l]
            l += 1
            if c.isdigit():
                temp += c
            else:
                if temp:
                    if m < temp.__len__():
                        res = temp
                        m = temp.__len__()

                    elif m == temp.__len__():
                        res += temp

                        m = temp.__len__()
                    temp = ''
        if temp:
            if m < temp.__len__():
                res = temp
                m = temp.__len__()

            elif m == temp.__len__():
                res += temp

                m = temp.__len__()

        print(res.strip() + ',' + str(m))        
    except:
        break
全部评论

相关推荐

代码飞升_不回私信人...:别这样贬低自己,降低预期,放平心态,跟昨天的自己比。做好自己,反而会效率更高心态更好,加油兄弟
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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