题解 | #在字符串中找出连续最长的数字串#
在字符串中找出连续最长的数字串
https://www.nowcoder.com/practice/2c81f88ecd5a4cc395b5308a99afbbec
只需要从头到尾扫描一次整个字符串;
while True: try: string = input() lst = [] max_len = 0 c = '' for i,s in enumerate(string): if s.isdigit(): c += s if not s.isdigit() or i==len(string)-1: if c !='' and len(c) >= max_len: if max_len == len(c): lst.append(c) elif max_len < len(c): lst.clear() lst.append(c) max_len = len(c) c = '' print(''.join(lst),max_len,sep=',') except: break