面经-字节跳动测试开发岗二面-输出最长连续数字串

str = 'abcd12345ed125ss123456789'
nums = []
tmp = []
Max_Length = 0
for each in str:
    if ord(each) <= ord('9') and ord(each) >= ord('0'):
        tmp.append(each)
    else :
        if len(tmp) > Max_Length:
            nums = []
            for every in tmp:
                nums.append(every)
            Max_Length = len(nums)
        else:
            tmp = []
if len(tmp) > Max_Length:
    nums = []
    for every in tmp:
        nums.append(every)
for each in nums:
    print(each, end="")

你可能感兴趣的:(面经)