美团笔试题-2019-10(部分)
1、美团 骑士送餐 分割最多子串 输出每个子串长度
"""
def solution(s):
length = len(s)
if length < 2:
return length
dic = {}
for i in range(length):
if dic.get(s[i]):
dic[s[i]][1] = i
else:
dic[s[i]] = [i, i]
print(dic)
li = list(dic.values())
print(li)
res = []
i = 0
l = 0
r = 0
while i < len(li):
if r > li[i][1]:
i+= 1
else:
if r < li[i][0]:
res.append(str(r-l+1))
l = li[i][0]
r = li[i][1]
i += 1
else:
r = li[i][1]
i += 1
res.append(str(r-l+1))
return ' '.join(res)
s = input()
print(solution(s))
"""