在python 3程序中大量案例耗时

时间:2019-07-13 07:11:12

标签: python python-3.x

我正在编写一个代码,该代码返回特定(用户输入)索引之前的char计数。大量输入的时间已用完。任何人都可以帮助我降低其时间复杂度。这是代码。

le=int(input())   #len string
st=input()        #string
tot=int(input())    # total cases
for i in range(tot):
    pos=int(input())  #index of char
    sub=st[0:pos]
    cou=sub.count(sub[pos-1])
    print(cou-1)

0 个答案:

没有答案