125
编辑日期: 2024-11-28 文章阅读: 次
@author jackzhenguo
@desc
@date 2019/11/14
125 寻找第n次出现位置
def search_n(s, c, n):
size = 0
for i, x in enumerate(s):
if x == c:
size += 1
if size == n:
return i
return -1
print(search_n("fdasadfadf", "a", 3))# 结果为7,正确
print(search_n("fdasadfadf", "a", 30))# 结果为-1,正确