1040. 有几个PAT(25)--Python

开始的时候最后三个测试点一直超时,然后借鉴了网上大佬的思路,立马过,跪拜

大佬的博

string = input()
list = list(string)
list.reverse()
count_T = 0 
count_AT = 0
count_PAT = 0
for num in list:
	if 'T' == num:
		count_T += 1
	elif 'A' == num:
		count_AT = (count_AT + count_T) % 1000000007
	else:
		count_PAT = (count_PAT + count_AT) % 1000000007
print(count_PAT)


你可能感兴趣的:(python,练习)